1.
Which declaration of the main method below would allow a class to be started as a standalone program. Select the one correct answer.
Correct Answer
B. Public static void main(String args[])
2.
What all gets printed when the following code is compiled and run? Select the three correct answers.
public class xyz {
public static void main(String args[]) {
for(int i = 0; i < 2; i++) {
for(int j = 2; j>= 0; j--) {
if(i == j) break;
System.out.println("i=" + i + " j="+j);
}
}
}
}
Correct Answer
A. I=0 j=1
3.
What gets printed when the following code is compiled and run with the following command -
java test 2
Select the one correct answer.
public class test {
public static void main(String args[]) {
Integer intObj=Integer.valueOf(args[args.length-1]);
int i = intObj.intValue();
if(args.length > 1)
System.out.println(i);
if(args.length > 0)
System.out.println(i - 1);
else
System.out.println(i - 2);
}
}
Correct Answer
D. 1
4.
-
In Java technology what expression can be used to represent number of elements in an array named arr ?
Correct Answer
B. Arr.length
5.
Is the following statement true or false. The constructor of a class must not have a return type.
Correct Answer
A. True
6.
Which of the following is a Java keyword. Select the four correct answers.
Correct Answer(s)
B. Synchronized
C. Volatile
F. Transient
G. This
7.
What is the number of bytes used by Java primitive long. Select the one correct answer
Correct Answer
D. 8
8.
Which of the following is correct? Select the correct answers.
Correct Answer
A. The native keyword indicates that the method is implemented in another language like C/C++.
9.
Which of the following are true. Select the one correct answers.
Correct Answer
A. && operator is used for short-circuited logical AND.
10.
Name the access modifier which when used with a method, makes it available to all the classes in the same package and to all the subclasses of the class.
Correct Answer
B. Protected
11.
Which of the following is true. Select the two correct answers.
Correct Answer(s)
A. A class that is abstract may not be instantiated.
C. A static variable indicates there is only one copy of that variable.
12.
Which of these statements are true. Select the two correct answers.
Correct Answer(s)
C. A try block must be followed by at least one finally or catch block.
D. If both catch and finally blocks are defined, catch block must precede the finally block.
13.
Which of these are core interfaces in the collection framework. Select the one correct answer.
Correct Answer
D. Map
14.
Name the keyword that makes a variable belong to a class, rather than being defined for each instance of the class. Select the one correct answer.
Correct Answer
A. Static
15.
Which of the following are correct. Select the one correct answer.
Correct Answer
D. Local variables cannot be declared as static
16.
Select the one correct answer. Which method defined in Integer class can be used to convert an Integer object to primitive int type.
Correct Answer
B. IntValue
17.
Select the one correct answer. The number of characters in an object of a class String is given by
Correct Answer
D. The method length() returns the number of characters.
18.
What is the result of compiling and running the following program.
public class test {
public static void main(String args[]) {
String str1="abc";
String str2="def";
String str3=str1.concat(str2);
str1.concat(str2);
System.out.println(str1);
}
}
Correct Answer
A. Abc
19.
Which of these classes defined in java.io and used for file-handling are abstract. Select the two correct answers.
Correct Answer(s)
A. InputStream
C. Reader
20.
Is the following statement true or false. As the toString method is defined in the Object class, System.out.println can be used to print any object.
Correct Answer
A. True
21.
What gets written on the screen when the following program is compiled and run. Select the one right answer.
public class test {
public static void main(String args[]) {
int i;
float f = 2.3f;
double d = 2.7;
i = ((int)Math.ceil(f)) * ((int)Math.round(d));
System.out.println(i);
}
}
Correct Answer
D. 9
22.
What is the return type of method round(double d) defined in Math class.
Correct Answer
A. Long
23.
Assume that class A extends class B, which extends class C. Also all the three classes implement the method test(). How can a method in a class A invoke the test() method defined in class C (without creating a new instance of class C). Select the one correct answer.
Correct Answer
D. It is not possible to invoke test() method defined in C from a method in A.
24.
Which of the following are true about interfaces. Select the one correct answers.
Correct Answer
B. Variables declared in interfaces are implicitly public, static, and final.
25.
In which all cases does an exception gets generated. Select the two correct answers.
int i = 0, j = 1;
Correct Answer(s)
B. If((i == 0) | (j/i == 1))
D. If((i != 0) & (j/i == 1))
26.
If a base class has a method defined as
void method() { }
Which of the following are legal prototypes in a derived class of this class. Select the two correct answers.
Correct Answer
C. Void method(int i) { }
27.
Which of the following statements related to Garbage Collection are correct. Select the two correct answers.
Correct Answer(s)
C. It is possible for a program to make an object available for Garbage Collection.
D. The finalize method of an object is invoked before garbage collection is performed on the object.
28.
String s = new String("xyz");
Assuming the above declaration, which of the following statements would compile. Select the one correct answer.
Correct Answer
C. S = s + s;
29.
At what stage in the following method does the object initially referenced by s becomes available for garbage collection. Select the one correct answer.
void method X() {
String r = new String("abc");
String s = new String("abc");
r = r+1; //1
r = null; //2
s = s + r; //3
} //4
Correct Answer
D. Before statement labeled 4
30.
Which of the following are legal identifier names in Java. Select the two correct answers.
Correct Answer(s)
B. $abcd
E. _a_long_name
31.
Which of these is a legal definition of a method named m assuming it throws IOException, and returns void. Also assume that the method does not take any arguments. Select the one correct answer.
Correct Answer
A. Void m() throws IOException{}
32.
What gets printed when the following code is compiled and run. Select the one correct answer.
public class test {
public static void main(String args[]) {
int i = 1;
do {
i--;
} while (i > 2);
System.out.println(i);
}
}
Correct Answer
A. 0
33.
How can you ensure that the memory allocated by an object is freed. Select the one correct answer.
Correct Answer
D. Garbage collection cannot be forced. The programmer cannot force the JVM to free the memory used by an object.
34.
What is the range of values that can be specified for an int. Select the one correct answer.
Correct Answer
A. -231 to 231 - 1
35.
Which of the following are legal array declarations. Select the three correct answers.
Correct Answer(s)
B. Int i[][];
C. Int []i[];
E. Int[][] a;
36.
What all gets printed when the following gets compiled and run. Select the two correct answers.
public class test {
public static void main(String args[]) {
String s1 = "abc";
String s2 = new String("abc");
if(s1 == s2)
System.out.println(1);
else
System.out.println(2);
if(s1.equals(s2))
System.out.println(3);
else
System.out.println(4);
}
}
Correct Answer(s)
B. 2
C. 3
37.
What all gets printed when the following gets compiled and run. Select the two correct answers.
public class test {
public static void main(String args[]) {
String s1 = "abc";
String s2 = "abc";
if(s1 == s2)
System.out.println(1);
else
System.out.println(2);
if(s1.equals(s2))
System.out.println(3);
else
System.out.println(4);
}
}
Correct Answer(s)
A. 1
C. 3
38.
What all gets printed when the following gets compiled and run. Select the three correct answers.
public class test {
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i/j > 1)
i++;
}
catch(ArithmeticException e) {
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(1);
}
catch(Exception e) {
System.out.println(2);
}
finally {
System.out.println(3);
}
System.out.println(4);
}
}
Correct Answer(s)
A. 0
D. 3
E. 4
39.
What all gets printed when the following program is compiled and run. Select the one correct answer.
public class test {
public static void main(String args[]) {
int i=0, j=2;
do {
i=++i;
j--;
} while(j>0);
System.out.println(i);
}
}
Correct Answer
C. 2
40.
What all gets printed when the following program is compiled and run. Select the two correct answers.
public class test {
public static void main(String args[]) {
int i, j=1;
i = (j>1)?2:1;
switch(i) {
case 0: System.out.println(0); break;
case 1: System.out.println(1);
case 2: System.out.println(2); break;
case 3: System.out.println(3); break;
}
}
}
Correct Answer(s)
B. 1
C. 2