1.
The constructor for the Math class is private, so it cannot be instaniated
Correct Answer
A. True
2.
class C {public static void main(String[] args) { int x=2; int y=3; if((y==x++)|(x<++y)){ System.out.println(x+""+y); }}}
Correct Answer
A. Prints 34
3.
interface I{final class C1 { //1 static int i=9;; //2 }}class C2 implements I{ public static void main(String a[]){ System.out.println(I.C1.i); ///3}}
Correct Answer
D. Prints 9
4.
class C{public static void main(String[] args) { try { try { try { } catch(RuntimeException e) { } } catch(Exception e) { } } catch(NullPointerException e) { } finally { System.out.println("finally"); }}}
Correct Answer
A. Prints finally
5.
class C { public static void main ( String ka [ ] ) { while ( false ) { System.out.println ( "Value" ) ; } }}
Correct Answer
A. Compile time error
6.
Class C {public static void main(String[] args) { System.out.println(4+5+"String");}}
Correct Answer
A. Prints 9string
7.
class H { public static void main (String[] args) { String s1 = "HHH"; StringBuffer sb2 = new StringBuffer(s1); System.out.print(sb2.equals(s1) + "," + s1.equals(sb2));}}
Correct Answer
A. Prints: false,false
8.
The relationship between a class and its superclass is
Correct Answer
B. Is -a
9.
class A extends Thread { private int i; public void run() {i = 1;} public static void main(String[] args) { A a = new A(); a.run(); System.out.print(a.i);}}How many threads are created in this Program?
Correct Answer
A. 1
10.
String objects once created can not be modified
Correct Answer
A. True
11.
Which of the following modifiers can be applied to a class that is not a nested class?
Correct Answer
A. Public
12.
if(0.0 == -0.0) { System.out.println("true");}else{ System.out.println("false");}
Correct Answer
B. Prints true
13.
class C {public static void main(String[] args) {double d1 = Math.floor(0.5);double d2 = Math.floor(1.5);System.out.print(d1 + "," + d2);}}
Correct Answer
A. Prints: 0.0,1.0
14.
System.out.println("String".substring(0,4));This statement will Print
Correct Answer
B. Will print "Stri"
15.
if("String".replace('t','T') == "String".replace('t','T'))System.out.println("Equal");elseSystem.out.println("Not Equal");
Correct Answer
B. Will Print Not Equal
16.
Which of the following classes will not allow unsynchronized read operations by multiple threads?
Correct Answer
A. Vector
17.
StringBuffer objects once created can not be modified
Correct Answer
B. False
18.
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[])
19.
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(s)
B. I=0 j=1
C. I=0 j=2
E. I=1 j=2
20.
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
21.
In Java technology what expression can be used to represent number of
elements in an array named arr ? ...........
Correct Answer
arr.length
22.
How would the number 5 be represented in hex using up-to four characters? ............
Correct Answer
0x5
0x05
0X05
0X5
23.
Is the following statement true or false. The constructor of a class must not have a return type.
Correct Answer
A. True
24.
Is the following statement true or false. The constructor of a class must not have a return type.
Correct Answer
A. True
25.
What is the number of bytes used by Java primitive long. Select the one correct answer.
Correct Answer
D. 8
26.
What is returned when the method substring(2, 4) is invoked on the
string "example"? Include the answer in quotes as the result is of type
String. .........
Correct Answer
"am"
27.
Which of the following is correct? Select the two correct answers.
Correct Answer(s)
A. The native keyword indicates that the method is implemented in another language like C/C++.
C. The method definitions inside interfaces are public and abstract. They cannot be private or protected.
28.
What is the result of evaluating the expression 14 ^ 23. Select the one correct answer
Correct Answer
A. 25
29.
Which of the following are true. Select the one correct answers
Correct Answer
A. && operator is used for short-circuited logical AND
30.
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
protected
31.
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.
32.
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
33.
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
34.
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[]) { int i=1, j=1; try { i++; j--; if(i == j) 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)
D. 3
E. 4
35.
19. 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
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.
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;
38.
What is the range of values that can be specified for an int. Select the one correct answer.
Correct Answer
B. -231 to 231 - 1
39.
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
40.
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
41.
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{}
42.
Which of the following are legal identifier names in Java. Select the two correct answers.
Correct Answer(s)
B. $abcd
E. _a_long_name
43.
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
44.
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;
45.
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
46.
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(s)
A. Void method() { }
C. Void method(int i) { }
47.
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))
48.
Which of the following statements are true. Select the two correct answers
Correct Answer(s)
B. The wait(), notify(), and notifyAll() methods must be executed in synchronized code.
C. The notify() and notifyAll() methods can be used to signal and move waiting threads to ready-to-run state.
49.
Which keyword when applied on a method indicates that only one thread
should execute the method at a time. Select the one correct answer
Correct Answer
C. Synchronized
50.
Which of the following are true about interfaces. Select the two correct answers.
Correct Answer(s)
B. Variables declared in interfaces are implicitly public, static, and final
C. An interface can extend any number of interfaces.