Question
Which statement about try-with-resources is the strongest interview answer?
- try-with-resources closes AutoCloseable resources reliably even when the main operation fails.
- try-with-resources is mostly a naming style choice and has little effect on runtime or design.
- try-with-resources exists mainly to reduce the number of Java files in a project.
- try-with-resources matters only for frontend frameworks, not for core Java applications.
Hint
Start with the core rule behind try-with-resources.
Answer and rationale
Correct answer: A. try-with-resources closes AutoCloseable resources reliably even when the main operation fails.
try-with-resources closes AutoCloseable resources reliably even when the main operation fails. This is the base concept interviewers commonly test first.
Track: Java