Skip to content
Sharp

Core Java · interview question

How does a try-with-resources statement differ from a regular try-catch-finally block?

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

Correct answer

B. It automatically closes resources.

Why

A try-with-resources statement automatically closes resources declared in the try statement's header when the block exits, whether normally or due to an exception. This reduces boilerplate code and ensures resources are properly closed.

Test yourself on Core Java

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

Start free test
All Core Java questions →