Difficulty: Easy
Correct Answer: Finally
Explanation:
Introduction / Context:
This question focuses on the guarantee that finally executes even if the try block returns, breaks, or continues. The JVM ensures the finally block runs before control leaves the method.
Given Data / Assumptions:
Concept / Approach:
Java specifies that the finally block executes after the try (and any matching catch) but before the method actually returns control to the caller. Therefore, the println in finally will run and produce output.
Step-by-Step Solution:
Verification / Alternative check:
Place code after the try/catch/finally; it will be unreachable because of the return, but the finally still runs first.
Why Other Options Are Wrong:
Compilation is valid; there is definite output; no exception is thrown.
Common Pitfalls:
Believing that return suppresses finally; in Java it does not.
Final Answer:
Finally
Discussion & Comments