Which digits, and in what order, will be printed when the following program is run?.
public class Main { public static void main(String[] args) throws InterruptedException { try {//from www . j a v a 2 s. c o m f(); System.out.println("1"); } finally { System.out.println("2"); } System.out.println("3"); } // InterruptedException is a direct subclass of Exception. static void f() throws InterruptedException { throw new InterruptedException("Time to go home."); } }
Select the one correct answer.
(a)
The program will print 2 and throw an InterruptedException.
An InterruptedException is thrown in the try block.
There is no catch block to handle the exception, so it will be sent to the caller of the main()
method, i.e., to the default exception handler.
Before this happens, the finally block is executed.
The code to print 3 is never reached.