Sie sind auf Seite 1von 7

1.

You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provides that capability? A. C. 2. java.util.Map java.util.List B. java.util.Set D. java.util.Collection

Which two statements are true?

Deadlock will not occur if wait()/notify() is used A thread will resume execution as soon as its sleep duration expires. Synchronization can prevent two objects from being accessed by the same thread. The wait() method is overloaded to accept a duration. The notify() method is overloaded to accept a duration. Both wait() and notify() must be called from a synchronized context. A. 1 and 2 C. 4 and 6 3. Which statement is true? A. Memory is reclaimed by calling Runtime.gc (). B. Objects are not collected if they are accessible from live threads. C. An OutOfMemory error is only thrown if a single block of memory cannot be found that is large enough for a particular requirement. D. Objects that have finalize() methods always have their finalize() methods called before the program ends. 4. What will be the output of the program? public class SqrtExample { public static void main(String [] args) { double value = -9.0; System.out.println( Math.sqrt(value)); } } A. 3.0 B.-3.0 C. NaN D.Compilation fails. 5. What will be the output of the program? String s = "hello"; Object o = s; if( o.equals(s) ) { System.out.println("A"); } else { B. 3 and 5 D. 1 and 3

System.out.println("B"); } if( s.equals(o) ) { System.out.println("C"); } else { System.out.println("D"); } 1.A 2.B 3.C 4.D A. 1 and 3 C. 3 and 4 B. 2 and 4 D. 1 and 2

6. What will be the output of the program? String a = "newspaper"; a = a.substring(5,7); char b = a.charAt(1); a = a + b; System.out.println(a); A.apa C.apea B.app D.apep

7.What will be the output of the program? public class Test { public static void main(String[] args) { final StringBuffer a = new StringBuffer(); final StringBuffer b = new StringBuffer(); new Thread() { public void run() { System.out.print(a.append("A")); synchronized(b) { System.out.print(b.append("B")); } } }.start(); new Thread()

{ public void run() { System.out.print(b.append("C")); synchronized(a) { System.out.print(a.append("D")); } } }.start(); } } A. ACCBAD C. CDDACB B. ABBCAD D. Indeterminate output

8. What will be the output of the program? String a = "ABCD"; String b = a.toLowerCase(); b.replace('a','d'); b.replace('b','c'); System.out.println(b); A. abcd C. dccd B. ABCD D. dcba

9.Which statement is true? A. Assertions can be enabled or disabled on a class-by-class basis. B. Conditional compilation is used to allow tested classes to run at full speed. C. Assertions are appropriate for checking the validity of arguments in a method. D. The programmer can choose to execute a return statement or to throw an exception if an assertion fails. 10.Which is true about an anonymous inner class? A. B. C. D. It can extend exactly one class and implement exactly one interface. It can extend exactly one class and can implement multiple interfaces. It can extend exactly one class or implement exactly one interface. It can implement multiple interfaces regardless of whether it also extends a class.

11.class HappyGarbage01 { public static void main(String args[]) { HappyGarbage01 h = new HappyGarbage01(); h.methodA(); /* Line 6 */ } Object methodA()

{ Object obj1 = new Object(); Object [] obj2 = new Object[1]; obj2[0] = obj1; obj1 = null; return obj2[0]; } } Where will be the most chance of the garbage collector being invoked? A. After line 9 B. After line 10 C. After line 11 D. Garbage collector never invoked in methodA() 12. public class Test { public void foo() { assert false; /* Line 5 */ assert false; /* Line 6 */ } public void bar() { while(true) { assert false; /* Line 12 */ } assert false; /* Line 14 */ } } What causes compilation to fail? A. Line 5 B. C. Line 12 D.

Line 6 Line 14

13. What will be the output of the program? public class X { public static void main(String [] args) { try { badMethod(); System.out.print("A"); } catch (Exception ex) { System.out.print("B");

} finally { System.out.print("C"); } System.out.print("D"); } public static void badMethod() { throw new Error(); /* Line 22 */ } } A. B. C. D. ABCD Compilation fails. C is printed before exiting with an error message. BC is printed before exiting with an error message.

14.What will be the output of the program? int x = 3; int y = 1; if (x = y) /* Line 3 */ { System.out.println("x =" + x); } A. x=1 B. x=3 C. Compilation fails. D. The code runs with no output. 15.Which one of the following will declare an array and initialize it with five numbers? A. Array a = new Array(5); B. int [] a = {23,22,21,20,19}; C. int a [] = new int[5]; D. int [5] array; 16.Which three are valid declarations of a char? char c1 = 064770; char c2 = 'face'; char c3 = 0xbeef; char c4 = \u0022; char c5 = '\iface'; char c6 = '\uface'; A. 1, 2, 4 B. 1, 3, 6 C. 3, 5 D. 5 only 17. public interface Foo

{ int k = 4; /* Line 3 */ } Which three piece of codes are equivalent to line 3? final int k = 4; public int k = 4; static int k = 4; abstract int k = 4; volatile int k = 4; protected int k = 4; A. 1, 2 and 3 B. 2, 3 and 4 C. 3, 4 and 5 D. 4, 5 and 6 18. Which statement is true for the class java.util.ArrayList? A. B. C. D. The elements in the collection are ordered. The collection is guaranteed to be immutable. The elements in the collection are guaranteed to be unique. The elements in the collection are accessed using a unique key.

19. class Test1 { public int value; public int hashCode() { return 42; } } class Test2 { public int value; public int hashcode() { return (int)(value^5); } } which statement is true? A. class Test1 will not compile. B. The Test1 hashCode() method is more efficient than the Test2 hashCode() method. C. The Test1 hashCode() method is less efficient than the Test2 hashCode() method. D. class Test2 will not compile. 20. In the given program, how many lines of output will be produced?

public class Test { public static void main(String [] args) { int [] [] [] x = new int [3] [] []; int i, j; x[0] = new int[4][]; x[1] = new int[2][];

x[2] = new int[5][]; for (i = 0; i < x.length; i++) { for (j = 0; j < x[i].length; j++) { x[i][j] = new int [i + j + 1]; System.out.println("size = " + x[i][j].length); } } } } A. C. 7 11 B. D. 9 13 E. Compilation fails

Das könnte Ihnen auch gefallen