Discussion :: Exceptions
-
What will be the output of the program?
public class Foo { public static void main(String[] args) { try { return; } finally { System.out.println( "Finally" ); } } }
- An exception arising in the finally block itself.
- The death of the thread.
- The use of System.exit()
- Turning off the power to the CPU.
A.
Finally |
B.
Compilation fails. |
C.
The code runs with no output. |
D.
An exception is thrown at runtime. |
Answer : Option A
Explanation :
If you put a finally block after a try and its associated catch blocks, then once execution enters the try block, the code in that finally block will definitely be executed except in the following circumstances:
I suppose the last three could be classified as VM shutdown.
Be The First To Comment