Oracle Certified Professional Java Se 8 Programmer · Free Practice Question Medium

Question 13

Given code of Test.java file: 

F: is accessible for reading/writing purposes.

Which of the following statement is true about above code?

  • A Compilation error
  • B

    Class Test compiles and executes fine and no output is displayed on to the console

  • C On execution, IOException is printed on to the console
Reveal correct answer

Correct answer: C

Explanation

Once the close() method is called on BufferedWriter, same stream cannot be used for writing.


bw.newLine(); tries to append a newline character to the closed stream and hence IOException is thrown.

catch handler is provided for IOException. Control goes inside and prints 'IOException' on to the console.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need