How many lines of text does the following program print?
package mypkg;/* w w w . jav a2 s .co m*/ import java.io.IOException; public class Main { public void m() throws IOException { new IOException("Not ready"); } public static void main(String[] b) throws Exception { try { new Main().m(); } catch (RuntimeException b) { // y1 System.out.println(b); throw new IOException(); // y2 } finally { System.out.println("complete"); } } }
C.
The code does not compile because the variable b is used twice in the main()
method, both in the method declaration and in the catch block.
Option C the correct answer.
If a different variable name was used in one of the locations, the program would print one line, complete, making Option A the correct answer.
Note that while an exception is created inside the m()
method, it is not thrown.