Java OCA OCP Practice Question 2889

Question

Given:

1. class MyException extends RuntimeException { }  
2. public class Main {  
3.   public static void main(String[] args) throws Exception {  
4.     throw new MyException();  
5.     System.out.println("success");  
6. } } 

Which are true? (Choose all that apply.)

  • A. The code runs without output.
  • B. The output "success" is produced.
  • C. Compilation fails due to an error on line 1.
  • D. Compilation fails due to an error on line 3.
  • E. Compilation fails due to an error on line 4.
  • F. Compilation fails due to an error on line 5.


F   is correct.

Note

The compiler sees that line 4 will always run, and therefore line 5 is unreachable.

If line 5 was removed, the rest of the code would be legal, and A would be correct.




PreviousNext

Related