Given that FileNotFoundException is a subclass of IOException, what is the output of the following application?
package mypkg; /* w ww.j a v a2 s. c o m*/ import java.io.*; public class Main { public void print() { try { throw new FileNotFoundException(); } catch (IOException exception) { System.out.print("Z"); } catch (FileNotFoundException enfe) { System.out.print("X"); } finally { System.out.print("Y"); } } public static void main(String... ink) { new Main().print(); } }
A.XY B.ZY C.The code does not compile. D.The code compiles but a stack trace is printed at runtime.
C.
The code does not compile because the catch blocks are used in the wrong order.
Since IOException is a superclass of FileNotFoundException, the FileNotFoundException is considered unreachable code.
The code does not compile, and Option C is correct.