Java OCA OCP Practice Question 2830

Question

Which of the following can legally fill in the blank? (Choose all that apply.)

public class Main { 
  static class Exception1 extends Exception { } 
  static class Exception2 extends Exception1 { } 
  public static void main(String[] args) throws Exception1 { 
     try { /*from  w w w  .ja  va2  s. c om*/
        throw new Exception1(); 
     } catch (Exception1 | Exception2 e) { 
          _________________ 
          throw e; 
     } 
  } 
} 
  • A. // leave line blank
  • B. e = new Exception();
  • C. e = new RuntimeException();
  • D. e = new Exception1();
  • E. e = new Exception2();
  • F. None of the above; the code does not compile.


F.

Note

A multi-catch cannot catch both a superclass and subclass.

Notice how similar questions can be while testing something that is entirely different.




PreviousNext

Related