Skip to content
Sharp

Exceptions · interview question

What happens if both the 'try' and 'finally' blocks contain return statements?

Multiple choiceHardchapter-6-curatedpremiumexceptionstry-catch-finally
java
try { return 1; } finally { return 2; }
Choose one answer
Answer and explanation

Correct answer

C. The return in 'finally' overrides the one in 'try'

Why

If both 'try' and 'finally' have return statements, the return in 'finally' overrides the one in 'try'. The 'finally' block is executed after 'try', affecting the flow.

Test yourself on Exceptions

A free test with instant, explained results. No account needed.

Start free test
All Exceptions questions →