Compilation of class A fails.
Line 28 prints the value 3 to System.out.
Line 28 prints the value 1 to System.out.
Compilation fails because of an error on line 28.
A runtime error occurs when line 25 executes.
第1题:
public class Threads5 { public static void main (String[] args) { new Thread(new Runnable() { public void run() { System.out.print(”bar”); } }).start(); } } What is the result?()
第2题:
class A { public A() { System.out.println(“hello from a”); } } class B extends A { public B () { System.out.println(“hello from b”); super(); } } public class Test { public static void main(String args[]) { A a = new B(); } } What is the result when main is executed?()
第3题:
1. public class A { 2. public void method1() { 3. B b=new B(); 4. b.method2(); 5. // more code here 6. } 7. } 1. public class B { 2. public void method2() { 3.C c=new C(); 4. c.method3(); 5. // more code here 6. } 7. } 1. public class C { 2. public void method3() { 3. // more code here 4. } 5. } Given: 25. try { 26. A a=new A(); 27. a.method1(); 28. } catch (Exception e) { 29. System.out.print(”an error occurred”); 30. } Which two are true if a NullPointerException is thrown on line 3 of class C?()
第4题:
1. public class A { 2. 3. private int counter = 0; 4. 5. public static int getInstanceCount() { 6. return counter; 7. } 8. 9. public A() { 10. counter++; 11. } 12. 13. } Given this code from Class B: 25.A a1 =new A(); 26. A a2 =new A(); 27. A a3 =new A(); 28. System.out.printIn(A.getInstanceCount() ); What is the result?()
第5题:
Compilation fails.
An exception is thrown at runtime.
The code executes and prints “running”.
The code executes and prints “runningrunning”.
The code executes and prints “runningrunningrunning”.
第6题:
Compilation fails.
ClassC is displayed.
The code runs with no output.
An exception is thrown at runtime.
第7题:
Inconceivable!
Dizzying intellect!
The code runs with no output.
An exception is thrown at runtime.
Compilation fails because of an error in line 22.
第8题:
Line 26 prints "a" to System.out.
Line 26 prints "b" to System.out.
An exception is thrown at line 26 at runtime.
Compilation of class A will fail due to an error in line 6.
第9题:
Compilation of class A fails.
Line 28 prints the value 3 to System.out.
Line 28 prints the value 1 to System.out.
A runtime error occurs when line 25 executes.
Compilation fails because of an error on line 28.
第10题:
Compilation fails.
hello from a
hello from b
hello from b hello from a
hello from a hello from b
第11题:
Compilation fails due to an error in line 23.
Compilation fails due to an error in line 29.
A ClassCastException occurs in line 29.
A ClassCastException occurs in line 31.
The value of all four objects prints in natural order.
第12题:
The code runs with no output.
An exception is thrown at runtime.
Compilation fails because of an error in line 20.
Compilation fails because of an error in line 21.
Compilation fails because of an error in line 23.
Compilation fails because of an error in line 25.
第13题:
10. interface A { void x(); } 11. class B implements A { public void x() { } public voidy() { } } 12. class C extends B { public void x() {} } And: 20. java.util.List list = new java.util.ArrayList(); 21. list.add(new B()); 22. list.add(new C()); 23. for (A a:list) { 24. a.x(); 25. a.y();; 26. } What is the result?()
第14题:
23. Object [] myObjects = { 24. new integer(12), 25. new String(”foo”), 26. new integer(5), 27. new Boolean(true) 28. }; 29. Arrays.sort(myObjects); 30. for( int i=0; i
第15题:
11. class Cup { } 12. class PoisonCup extends Cup { } 21. public void takeCup(Cup c) { 22. if(c instanceof PoisonCup) { 23. System.out.println(”Inconceivable!”); 24. } else if(c instanceof Cup) { 25. System.out.println(”Dizzying intellect!”); 26. } else { 27. System.exit(0); 28. } 29. } And the execution of the statements: Cup cup = new PoisonCup(); takeCup(cup); What is the output?()
第16题:
1. public class A { 2. public String doit(int x, int y) { 3. return “a”; 4. } 5. 6. public String doit(int... vals) { 7. return “b”; 8. } 9. } Given: 25. A a=new A(); 26. System.out.println(a.doit(4, 5)); What is the result?()
第17题:
Line 26 prints “a” to System.out.
Line 26 prints „b” to System.out.
An exception is thrown at line 26 at runtime.
Compilation of class A will fail due to an error in line 6.
第18题:
Compilation of class A fails.
Line 28 prints the value 3 to System.out.
Line 28 prints the value 1 to System.out.
A runtime error occurs when line 25 executes.
Compilation fails because of an error on line 28.
第19题:
The code runs with no output.
Compilation fails.
An exception is thrown at runtime.
ClassC is displayed.
第20题:
Compilation fails.
An exception is thrown at runtime.
The code executes normally and prints “bar”.
The code executes normally, but nothing prints.
第21题:
Compilation of class A fails.
Line 28 prints the value 3 to System.out.
Line 28 prints the value 1 to System.out.
A runtime error occurs when line 25 executes.
Compilation fails because of an error on line 28.
第22题:
The application will crash.
The code on line 29 will be executed.
The code on line 5 of class A will execute.
The code on line 5 of class B will execute.
The exception will be propagated back to line 27.
第23题:
Compilation of class A fails.
Line 28 prints the value 3 to System.out.
Line 28 prints the value 1 to System.out.
A runtime error occurs when line 25 executes.
Compilation fails because of an error on line 28.