Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Oracle Exam 1Z0-809 Topic 14 Question 65 Discussion

Actual exam question for Oracle's 1Z0-809 exam
Question #: 65
Topic #: 14
[All 1Z0-809 Questions]

Given the code fragment:

public static void main (String[] args) throws IOException {

BufferedReader brCopy = null;

try (BufferedReader br = new BufferedReader (new FileReader(''employee.txt''))) { //

line n1

br.lines().forEach(c -> System.out.println(c));

brCopy = br;//line n2

}

brCopy.ready(); //line n3;

}

Assume that the ready method of the BufferedReader, when called on a closed BufferedReader, throws an exception, and employee.txt is accessible and contains valid text.

What is the result?

Show Suggested Answer Hide Answer
Suggested Answer: D

Contribute your Thoughts:

Andree
22 hours ago
The correct answer is D. The code will print the content of the employee.txt file and throw an exception at line n3. This is because the BufferedReader is closed at the end of the try-with-resources block, but we're still trying to call the ready() method on the brCopy reference, which will result in an exception.
upvoted 0 times
...
Kanisha
13 days ago
Hmm, that makes sense too. Let's see what others think before making a final decision.
upvoted 0 times
...
Zana
16 days ago
I disagree, I believe the answer is D) because the code will print the content of the file before throwing an exception at line n3.
upvoted 0 times
...
Kanisha
21 days ago
I think the answer is A) because calling ready() on a closed BufferedReader will throw an exception.
upvoted 0 times
...

Save Cancel