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

Question 26

F: is accessible for reading/writing and below is the directory structure for F:

Book.java is a text file.
            
Given code of Test.java file: 


What will be the result of compiling and executing Test class?

  • A Compilation error
  • B An exception is thrown at runtime.
  • C Contents of Book.java are printed on to the console.
Reveal correct answer

Correct answer: C

Explanation

Files class has methods such as newInputStream(...), newOutputStream(...), newBufferedReader(...) and newBufferedWriter(...) for files reading and writing.

Given code doesn't cause any compilation error.


As Book.java is a text file and accessible, hence its contents are printed 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