Courseiva
Handling ExceptionsmediumMultiple SelectObjective-mapped

1Z0-829 Handling Exceptions Practice Question

Which TWO statements about try-with-resources are correct? (Choose two.)

⚠ Common exam trap

Test-takers frequently confuse the closing order with declaration order or mistakenly think `Closeable` is required instead of `AutoCloseable`, leading them to select options B or C.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Resources are closed in the reverse order of their declaration.

The Java Language Specification (JLS §14.20.3) mandates that resources declared in a try-with-resources statement are closed in the reverse order of their declaration. This ensures that if a resource depends on another declared earlier, the dependent resource is closed first, preventing resource leaks or inconsistent states.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Resources are closed in the reverse order of their declaration.

    Why this is correct

    Correct; last declared resource closed first.

  • Resources are closed in the same order as their declaration.

    Why it's wrong here

    Incorrect; reverse order.

  • Resources declared in try-with-resources must implement the Closeable interface.

    Why it's wrong here

    They must implement AutoCloseable, not necessarily Closeable (though Closeable extends AutoCloseable).

  • Resources declared earlier in the try clause are closed first.

    Why it's wrong here

    Incorrect; resources are closed in reverse order.

  • If an exception is thrown from the try block and another from a resource's close() method, the try block exception propagates and the close() exception is added as a suppressed exception.

    Why this is correct

    The try exception is primary, close exceptions are suppressed.

About these practice questions

This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.