Practice Test Geeks home

OCP - Oracle Certified Professional OCP Exception Handling and Assertions Questions and Answers

Examine the following code which uses a try-with-resources statement.
What is the output when this code is executed?

```java

class Door implements AutoCloseable {

private String name;

public Door(String name) { this.name = name; System.out.println(name + " opened"); }

@Override

public void close() { System.out.println(name + " closed"); }

}

public class Test {

public static void main(String[] args) {

try (Door front = new Door("Front"); Door back = new Door("Back")) {

System.out.println("Walking through doors");

}

}

}

```

Select your answer