Which two modifications enable the code to print Open Close?

Given:
final class Folder { //line n1
//line n2
public void open () {
System.out.print(“Open”);
}
}
public class Test {
public static void main (String [] args) throws Exception {
try (Folder f = new Folder()) {
f.open();
}
}
}
Which two modifications enable the code to print Open Close?

Given:
final class Folder { //line n1
//line n2
public void open () {
System.out.print(“Open”);
}
}
public class Test {
public static void main (String [] args) throws Exception {
try (Folder f = new Folder()) {
f.open();
}
}
}
Which two modifications enable the code to print Open Close?

A.
Replace line n1 with:
class Folder implements AutoCloseable {

B.
Replace line n1 with:
class Folder extends Closeable {

C.
Replace line n1 with:
class Folder extends Exception {

D.
At line n2, insert:
final void close () {
System.out.print(“Close”);
}

E.
At line n2, insert:
public void close () throws IOException {
System.out.print(“Close”);
}



Leave a Reply 3

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


CompileTester

CompileTester

A, E

smh

smh

A, E
prints, OpenClose

andrei

andrei

A, E
In order to use Try with resources, class have to implement Closeable or AutoCloseable and @Override close() method. Only hint is A, E.