Java OCA OCP Practice Question 2925

Question

Given that FileNotFoundException extends IOException and given:

2. import java.io.*;  
3. public class Main {  
4.   public static void main(String[] args) throws IOException {  
5.     new Main().go();  
6.     new Main().go2();  
7.     new Main().go3();  
8.   }  /*from ww  w  .  j  av  a 2s  . c  om*/
9.   void go() { throw new IllegalArgumentException(); }  
10.   
11.   void go2() throws FileNotFoundException { }  
12.    
13.   void go3() {  
14.     try { throw new Exception(); }  
15.     catch (Throwable th) { throw new NullPointerException(); }  
16. } } 

What is the result? (Choose all that apply.)

  • A. An IOException is thrown at runtime.
  • B. A NullPointerException is thrown at runtime.
  • C. An IllegalArgumentException is thrown at runtime.
  • D. Compilation fails due to an error at line 4.
  • E. Compilation fails due to an error at line 9.
  • F. Compilation fails due to an error at line 11.
  • G. Compilation fails due to an error at line 15.


C is correct.

Note

It's legal for main() to throw an exception, and it's legal to catch a checked exception and re-throw a runtime exception.




PreviousNext

Related