In what order are the resources declared in a Java try-with-resources statement closed?
Correct answer C. In the reverse order of their declaration
Explanation
Resources are initialised from left to right and closed in reverse order, so a resource that depends on an earlier one is closed first. Closing happens automatically when the block exits, whether normally or through an exception, and it does not rely on garbage collection. Any exception from close is added as suppressed if another is already propagating.
Answer checked How we write and check questions
Discussion