Courseiva
Controlling Program FlowhardMultiple ChoiceObjective-mapped

1Z0-829 Controlling Program Flow Practice Question

A method contains a try-with-resources statement that uses two resources: a FileInputStream and a BufferedInputStream. The FileInputStream constructor throws a FileNotFoundException. Which statement about resource closing is true?

⚠ Common exam trap

Many exam-takers assume all declared resources are always closed, forgetting that the try-with-resources statement only closes resources that were successfully created, and an exception during construction of the first resource prevents the second from even being declared.

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

No resources are closed because the FileInputStream constructor failed before any resource was opened.

In a try-with-resources statement, resources are closed only if they have been successfully initialized. If the FileInputStream constructor throws a FileNotFoundException, the resource is never created, so the try-with-resources statement does not attempt to close it. The BufferedInputStream is never constructed because the exception occurs before its declaration is reached, so no resources are opened and none need to be closed. Therefore, option C is correct.

Answer analysis

Option-by-option breakdown

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

  • The BufferedInputStream is closed if it was successfully created, but the FileInputStream is not.

    Why it's wrong here

    The BufferedInputStream is declared second and would not be opened if the first failed.

  • Both resources are closed even if the FileInputStream constructor throws an exception.

    Why it's wrong here

    Only successfully opened resources are closed.

  • No resources are closed because the FileInputStream constructor failed before any resource was opened.

    Why this is correct

    The first constructor threw an exception, so no resource was opened.

  • The programmer must explicitly close the resources in a finally block.

    Why it's wrong here

    Try-with-resources closes resources automatically.

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.