Java OCA OCP Practice Question 3044

Question

Given:

3. public static void main(String[] args) {  
4.   try {  /*from   ww  w. j  av a2 s . c o  m*/
5.     throw new Error();  
6.   }  
7.   catch (Error e) {  
8.     try { throw new RuntimeException(); }  
9.     catch (Throwable t) { }  
10.   }  
11.   System.out.println("phew");  
12. } 

Which are true? (Choose all that apply.)

  • A. The output is phew
  • B. The code runs without output.
  • C. Compilation fails due to an error on line 5.
  • D. Compilation fails due to an error on line 7.
  • E. Compilation fails due to an error on line 8.
  • F. Compilation fails due to an error on line 9.


A is correct.

Note

It's legal to throw and handle errors and runtime exceptions.RuntimeException is a sub-subclass of Throwable.

B is incorrect because the code produces "phew".




PreviousNext

Related