单项选择题

1. public class a { 
2. public void method1() { 
3. try { 
4. B b=new b(); 
5. b.method2(); 
6. // more code here 
7. } catch (TestException te) { 
8. throw new RuntimeException(te); 
9. } 
10. } 
11. } 
1. public class b { 
2. public void method2() throws TestException { 
3. // more code here 
4. } 
5. } 
1. public class TestException extends Exception { 
2. }
 Given: 
31. public void method() { 
32. A a=new a(); 
33. a.method1(); 
34. } 
Which is true if a TestException is thrown on line 3 of class b?()

A. Line 33 must be called within a try block.
B. The exception thrown by method1 in class a is not required to be caught.
C. The method declared on line 31 must be declared to throw a RuntimeException.
D. On line 5 of class a, the call to method2 of class b does not need to be placed in a try/catch block.


您可能感兴趣的试卷

你可能感兴趣的试题

3.单项选择题

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. new B().process(); 
19. } 
What is the result?() 

A. B
B. The code runs with no output.
C. Compilation fails because of an error in line 12.
D. Compilation fails because of an error in line 15.
E. Compilation fails because of an error in line 18.

4.单项选择题

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?() 

A. B
B. The code runs with no output.
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 15.
E. Compilation fails because of an error in line 18.
F. Compilation fails because of an error in line 19.

8.多项选择题

Class TestException 
1. public class TestException extends Exception { 
2. } Class a: 
1. public class a { 
2. 
3. public String sayHello(String name) throws TestException { 
4. 
5. if(name == null) { 
6. throw new TestException(); 
7. } 
8. 
9. return “Hello “+ name; 
10. } 
11. 
12. } 
A programmer wants to use this code in an application:
45. A a=new A(); 
46. System.out.println(a.sayHello(”John”)); 
Which two are true?()

A. Class a will not compile.
B. Line 46 can throw the unchecked exception TestException.
C. Line 45 can throw the unchecked exception TestException.
D. Line 46 will compile if the enclosing method throws a TestException.
E. Line 46 will compile if enclosed in a try block, where TestException is caught.

9.单项选择题

public class SomeException { 
} Class a: 
public class a { 
public void doSomething() { } 
} Class b: 
public class b extends a { 
public void doSomething() throws SomeException { } 
} 
Which is true about the two classes?() 

A. Compilation of both classes will fail.
B. Compilation of both classes will succeed.
C. Compilation of class a will fail. Compilation of class b will succeed.
D. Compilation of class a will fail. Compilation of class a will succeed.

10.单项选择题

23.int z=5; 
24. 
25. public void stuff1(int x) { 
26. assert (x> 0); 
27. switch(x) { 
28. case 2: x= 3; 
29. default: assert false; } } 
30. 
31. private void stuff2(int y) { assert (y < 0); } 
32. 
33. private void stuff3() { assert (stuff4O); }
34. 
35. private boolean stuff4() { z = 6; return false; } 
Which is true?() 
 

A. All of the assert statements are used appropriately.
B. Only the assert statement on line 31 is used appropriately.
C. The assert statements on lines 29 and 31 are used appropriately.
D. The assert statements on lines 26 and 29 are used appropriately.
E. The assert statements on lines 29 and 33 are used appropriately.
F. The assert statements on lines 29, 31, and 33 are used appropriately.
G. The assert statements on lines 26, 29, and 31 are used appropriately.