Given:
Which statement is true?
Given:
Which statement is true?
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.
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
that is ok!
Tested A
A is correct cause, Class implement autoclosable and can variables declarated before try catch