1Z0-805 · Question #23
Which two statements are true regarding the try with resources statement?
The correct answer is B. In a try with resources statement, any catch or finally block is run after the resources have been closed. D. All the resources must implement the java.io.closeable interface. B: Prior to Java SE 7, you can use a finally block to ensure that a resource is closed regardless of whether the try statement completes normally or abruptly. A try-with-resources statement can have catch and finally blocks just like an ordinary trystatement. In a…
Question
Which two statements are true regarding the try with resources statement?
Options
- AThe resources declared in a try with resources statement are not closed automatically if an exception
- BIn a try with resources statement, any catch or finally block is run after the resources have been closed.
- CThe close methods of resources are called in the reverse order of their creation.
- DAll the resources must implement the java.io.closeable interface.
How the community answered
(70 responses)- A11% (8)
- B83% (58)
- C6% (4)
Explanation
B: Prior to Java SE 7, you can use a finally block to ensure that a resource is closed regardless of whether the try statement completes normally or abruptly. A try-with-resources statement can have catch and finally blocks just like an ordinary trystatement. In a try-with-resources statement, any catch or finally block is run after the resources declared have been closed. D:The try-with-resources statement is a try statement that declares one or more resources. Oracle 1Z0-805 Exam Aresource is an object that must be closed after the program is finished with it. The try-with- resources statement ensures that each resource is closed at the end of the statement. Any object that implements java.lang.AutoCloseable, which includes all objects which implementjava.io.Closeable, can be used as a resource.
Topics
Community Discussion
No community discussion yet for this question.