Compilation fails because of an error in line 19.
An exception is thrown at runtime.
B
Compilation fails because of an error in line 18.
Compilation fails because of an error in line 15.
The code runs with no output.
第1题:
public class Test { public static void aMethod() throws Exception { try { throw new Exception(); } finally { System.out.println(“finally”); } } public static void main(String args[]) { try { aMethod(); } catch (Exception e) { System.out.println(“exception”); } System.out.println(“finished”); } } What is the result?()
第2题:
1. public class Test { 2. public static String output =””; 3. 4. public static void foo(int i) { 5. try { 6. if(i==1) { 7. throw new Exception(); 8. } 9. output += “1”; 10. } 11. catch(Exception e) { 12. output += “2”; 13. return; 14. } 15. finally { 16. output += “3”;17. } 18. output += “4”; 19. } 20. 21. public static void main(String args[]) { 22. foo(0); 23. foo(1); 24. 25. }26. } What is the value of the variable output at line 23?()
第3题:
11. class Person { 12. String name = “No name‟; 13. public Person(String nm) { name = nm; } 14. } 15. 16. class Employee extends Person { 17. String emplD = “0000”; 18. public Employee(String id) { empID = id; } 19. } 20. 21. public class EmployeeTest { 22. public static void main(String[] args) { 23. Employee e = new Employee(”4321”); 24. System.out.println(e.empID); 25. } 26. } What is the result?()
第4题:
10. interface Foo {} 11. class Alpha implements Foo {} 12. class Beta extends Alpha {} 13. class Delta extends Beta { 14. public static void main( String[] args) { 15. Beta x = new Beta(); 16. // insert code here 17. } 18. } Which code, inserted at line 16, will cause a java.lang.ClassCastException?()
第5题:
11.classa { 12. public void process() { System.out.print(”a,”); } } 13. class b extends a { 14. public void process() throws IOException { 15. super.process(); 16. System.out.print(”b,”); 17. throw new IOException(); 18. } } 19. public static void main(String[] args) { 20. try { new b().process(); } 21. catch (IOException e) { System.out.println(”Exception”); } } What is the result?()
第6题:
Given: 11. static class A { 12. void process() throws Exception { throw new Exception(); } 13. } 14. static class B extends A { 15. void process() { System.out.println("B "); } 16. } 17. public static void main(String[] args) { 18. A a = new B(); 19. a.process(); 20. } What is the result? ()
第7题:
42
0042
An exception is thrown at runtime.
Compilation fails because of an error in line 13.
Compilation fails because of an error in line 14.
第8题:
4321
0000
An exception is thrown at runtime.
Compilation fails because of an error in line 18.
第9题:
Exception
A Exception
A Exception B
A B Exception
Compilation fails because of an error in line 14.
Compilation fails because of an error in line 19.
第10题:
TestA
TestB
Compilation fails.
An exception is thrown at runtime.
第11题:
B
The code runs with no output.
Compilation fails because of an error in line 12.
Compilation fails because of an error in line 15.
Compilation fails because of an error in line 18.
第12题:
Exception
a,b,Exception
Compilation fails because of an error in line 20.
Compilation fails because of an error in line 14.
A NullPointerException is thrown at runtime.
第13题:
11. class Converter { 12. public static void main(String[] args) { 13. Integer i = args[0]; 14. int j = 12; 15. System.out.println(”It is “ + (j==i) + “that j==i.”); 16. } 17. } What is the result when the programmer attempts to compile the code and run it with the command java Converter 12?()
第14题:
11.classA { 12. public void process() { System.out.print(”A “); } } 13. class B extends A { 14. public void process() throws RuntimeException { 15. super.process(); 16. if (true) throw new RuntimeException(); 17. System.out.print(“B”); }} 18. public static void main(String[] args) { 19. try { ((A)new B()).process(); } 20. catch (Exception e) { System.out.print(”Exception “); } 21. } What is the result?()
第15题:
public class Starter extends Thread { private int x= 2; public static void main(String[] args) throws Exception { new Starter().makeItSo(); } public Starter() { x=5; start(); } public void makeItSo() throws Exception { join(); x=x- 1; System.out.println(x); } public void run() { x *= 2; } } What is the output if the main() method is rum?()
第16题:
11. public static void append(List list) { list.add(”0042”); } 12. public static void main(String[] args) { 13. List
第17题:
11. static classA { 12. void process() throws Exception { throw new Exception(); } 13. } 14. static class B extends A { 15. void process() { System.out.println(”B “); } 16. } 17. public static void main(String[] args) { 18.A a=new B(); 19. a.process(); 20.} What is the result?()
第18题:
B
The code runs with no output.
An exception is thrown at runtime.
Compilation fails because of an error in line 15.
Compilation fails because of an error in line 18.
Compilation fails because of an error in line 19.
第19题:
Alpha a = x;
Foo f= (Delta)x;
Foo f= (Alpha)x;
Beta b = (Beta)(Alpha)x;
第20题:
42
An exception is thrown at runtime.
Compilation fails because of an error on line 12.
Compilation fails because of an error on line 16.
Compilation fails because of an error on line 17.
第21题:
4
5
8
9
Compilation fails.
An exception is thrown at runtime.
It is impossible to determine for certain.
第22题:
Compilation fails because of an error in line 19.
An exception is thrown at runtime.
B
Compilation fails because of an error in line 18.
Compilation fails because of an error in line 15.
The code runs with no output.
第23题:
finally
exception finished
finally exception finished
Compilation fails.
第24题:
It is true that j==i.
It is false that j==i.
An exception is thrown at runtime.
Compilation fails because of an error in line 13.