Consider the following code snippet written in Java 7:
Try (PrintWriter outputFile = new PrintWriter(filename) )
{
WriteData(outputFile) ;
}
Which of the following statements about this Java 7 code is correct?
A) The program will terminate with an unhandled exception if the PrintWriter constructor fails.
B) The close method of the outputFile object will be automatically invoked when the try block ends, but only if no exception occurred.
C) The close method of the outputFile object will be automatically invoked when the try block ends, but only if an exception occurs.
D) The close method of the outputFile object will be automatically invoked when the try block ends, whether or not an exception has occurred.
Correct Answer:
Verified
Q81: When a program throws an exception within
Q83: When writing a method, which of the
Q87: The Java compiler requires that your program
Q92: Which of the following statements about checked
Q92: Consider the following code snippet:
Public void readFile(String
Q93: Consider the following code snippet:
Public double[] readInputFile(String
Q98: Insert the missing code in the following
Q99: Which of the following statements about the
Q99: Consider the following code snippet:
Try
{
PrintWriter outputFile =
Q104: Consider the following code snippet: Scanner in
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents