Skip to content
Sharp

Core Java · interview question

Given a try-catch-finally block if a return statement is executed in both the try and finally blocks, what outcome should you expect?

Multiple choiceEasychapter-6-curatedpremiumcore-javacode-reading-with-exceptions
Choose one answer
Answer and explanation

Correct answer

C. The return statement in the finally block will be executed.

Why

In Java, if both try and finally blocks contain return statements, the return statement in the finally block overrides the one in the try block. The finally block is executed after the try block, ensuring that any final cleanup code is run.

Test yourself on Core Java

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

Start free test
All Core Java questions →