Which two statements are true regarding the try with resources statement?

Which two statements are true regarding the try with resources statement?

Which two statements are true regarding the try with resources statement?

A.
The resources declared in a try with resources statement are not closed automatically if an
exception occurs inside the try block.

B.
In a try with resources statement, any catch or finally block is run after the resources have been
closed.

C.
The close methods of resources are called in the reverse order of their creation.

D.
All the resources must implement the java.io.closeable interface.

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.
Aresource is an object that must be closed after the program is finished with it. The try-withresources 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.
Reference: The Java Tutorials,The try-with-resources Statement



Leave a Reply 2

Your email address will not be published. Required fields are marked *


zzZZzzzzZZzzz

zzZZzzzzZZzzz

BC
D is not corect.
must implement java.lang.AutoCloseable
Any object that implements java.lang.AutoCloseable, which includes all objects which implement java.io.Closeable, can be used as a resource.

thiago

thiago

it’s inverted, Closeable extends Autocloseable interface.

But I in doubt because letter C is correct too