Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The try-with-resources construct allows for better management of certain types o

ID: 3606722 • Letter: T

Question

The try-with-resources construct allows for better management of certain types of resources by letting the JVM handle automatically closing them whether execution terminates normally or abnormally. There is a key requirement which must be met in order for a type to be a candidate for management in a try-with-resources. Here is an example:

try (BufferedReader br = new BufferedReader(new FileReader("/path/to/some/file"))) {

    // Do something with the data from the file

}

Which of the following types are NOT able to appear in the parenthetical part of a try-with-resources?

Question options:

a) LogStream

b) PrintWriter

c) FileInputStream

d) Socket

e) None of these

Explanation / Answer

Answer: e) None of these

Above all types are able to appear in the parenthetical part of a try-with-resources

so Option e is the correct answer.