Java OCA OCP Practice Question 3024

Question

Given:

1. import java.io.*;  
2. public class Main {   
3.   public static void main(String[] args) {  
4.     try {  //ww  w  . ja  v a  2 s  .c  o m
5.       wow();  
6.       // throw new IOException();  
7.     } finally {  
8.       // throw new Error();  
9.       // throw new IOException();  
10.     }  
11.   }  
12.   static void wow() {  
13.     // throw new IllegalArgumentException();  
14.     // throw new IOException();  
15. } } 

And given that IOException is a direct subclass of java.lang.Exception, and that IllegalArgumentException is a runtime exception, which of the following, if uncommented independently, will compile? (Choose all that apply.).

  • A. Line 6
  • B. Line 8
  • C. Line 9
  • D. Line 13
  • E. Line 14
  • F. The code will NOT compile as is.


B and D are correct.

Note

B will compile because Errors are "unchecked" by the compiler.

D will compile because runtime exceptions are also "unchecked.".

A is incorrect because the IOException is not caught.

C and E are incorrect because the IOException is neither handled nor declared.

F is incorrect based on the above.




PreviousNext

Related