Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 202

Given:

Which statement is true?

    Correct Answer: A

    The code compiles successfully as it uses the try-with-resources statement correctly. In Java 9 and above, a resource that is effectively final (i.e., not reassigned after initialization) can be used in a try-with-resources statement without needing a new variable declaration inside the try block. The MyResource class implements AutoCloseable, which is sufficient for the try-with-resources statement. Therefore, the code provided will compile without any errors.

Discussion
ASPushkinOption: A

right answer is A //JDK 7 One one = new One(); // final One one = new One(); try (One temp = one; .....;) { //JDK9 One one = new One(); try(one) { and "one" is an effectively final

d7bb0b2

that is ok!

cathDevOption: A

Tested A

d7bb0b2Option: A

A is correct cause, Class implement autoclosable and can variables declarated before try catch