15 * 1= 15
1. Which of the following is a valid identifier?
a) 2name
b) studentName
c) student-name
d) class
[Link] is the size of a double in Java?
a) 4 bytes
b) 8 bytes
c) 2 bytes
d) 16 bytes
[Link] of the following is not a primitive datatype?
a) boolean
b) String
c) char
d) int
[Link] operator is used for typecasting?
a) =
b) ( )
c) ->
d) :
5. Which memory area stores variables created using Wrapper Classes?
a) Stack
b) Heap
c) String Pool
d) Register
[Link] method is used to convert a String to an int?
a) [Link]()
b) [Link]()
c) [Link]()
d) [Link]()
[Link] of the following is a valid single-line comment in Java?
a) // comment
b) /* comment */
c) # comment
d) – comment
[Link] converts:
a) Primitive → Wrapper
b) Wrapper → Primitive
c) String → Integer
d) Object → Class
[Link] memory area stores string literals?
a) Heap
b) Stack
c) String Pool
d) Register
[Link] method is used to compare string content?
a) ==
b) equals()
c) compare()
d) match()
11. Which method converts a string "12.5" into a double?
a) [Link]("12.5")
b) [Link]("12.5")
c) [Link]("12.5")
d) [Link]("12.5")
[Link] operator is used for increment?
a) ++
b) --
c) +=
d) +
[Link] is the default value of a boolean?
a) true
b) false
c) null
d) 0
[Link] datatype is used to store a single Unicode character?
a) String
b) char
c) Character
d) text
[Link] of the following is a valid way to declare a main method?
a) public static void main(String args[])
b) public void main(String args[])
c) static public void main(String args[])
d) Both a & c
SECTION-02 5 * 3=15
16)What is the output of below code snippet?
1) class Test {
public static void main(String[] args) {
int x = 5;
[Link](x++ + ++x);
}
}
2) class Demo {
public static void main(String[] args) {
int a = 10, b = 20;
[Link](a > b && b > a);
}
}
3) class Test {
public static void main(String[] args) {
String s1 = new String("hello");
String s2 = "hello";
[Link](s1 == s2);
}
}
4) class Wrap {
public static void main(String[] args) {
Integer a = 100;
Integer b = 100;
[Link](a == b);
}
}
5) class AutoBox {
public static void main(String[] args) {
int x = 50;
Integer y = x; // autoboxing
int z = y; // unboxing
[Link](x + y + z);
}
}
SECTION -3
Programming Questions:
4 * 5=20
1)Write a Java program to parse a string "12345" into an integer, add 10 to it, and print
the result.
2)Why is Java called a platform-independent language?
3)Write a Java program to show that two string literals with the same value point to the
same reference in the string pool, while two new String("...") objects do not. Print results
using ==.
4)What is the difference between primitive and non-primitive data types?