Java OCA OCP Practice Question 2968

Question

Given:

2. public class Main {  
3.   public static void main(String[] args) {  
4.     try {  /* w  w  w .j a  va2  s.  c  om*/
5.       assert(!args[0].equals("x")): "kate";  
6.     } catch(Error e) { System.out.print("ae "); }  
7.     finally {  
8.       try {  
9.         assert(!args[0].equals("y")): "jane";  
10.       } catch(Exception e2) { System.out.print("ae2 "); }  
11.       finally {  
12.         throw new IllegalArgumentException();  
13. } } } } 

And, if the code compiles, the invocation:

java -ea Main y 

Which will be included in the output? (Choose all that apply.)

  • A. ae
  • B. ae2
  • C. kate
  • D. jane
  • E. AssertionError
  • F. IllegalArgumentException
  • G. There is no output because compilation fails.


F   is correct.

Note

Line 9 throws an AssertionError (which the second catch statement cannot catch).

Before it can be reported, the second finally statement MUST run, which throws IllegalArgumentException, so the AssertionError never gets reported.




PreviousNext

Related