Question:

What will happen if a return statement is present inside a try block and also in the finally block?

Show Hint

finally always runs before the method returns, and a return there overrides any return set in try.
Updated On: Jul 2, 2026
  • Compilation error
  • Both return statements will execute
  • The return statement inside the finally block will execute
  • The return statement inside the try block will execute
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

Step 1: In Java the finally block always runs before the method actually hands back control, even when the try block has already prepared a return value.

Step 2: When the try block hits its return, Java holds that value but still enters finally first.

Step 3: If finally has its own return, that new return replaces the earlier one. The value from try is thrown away.

Step 4: So the return inside finally is the one that takes effect. Answer is (C).
Was this answer helpful?
0
0