exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 28 discussion

Actual exam question from Oracle's 1z0-809
Question #: 28
Topic #: 1
[All 1z0-809 Questions]

Given:
class ImageScanner implements AutoCloseable {
public void close () throws Exception {
System.out.print ("Scanner closed.");
}
public void scanImage () throws Exception {
System.out.print ("Scan.");
throw new Exception("Unable to scan.");
}
}
class ImagePrinter implements AutoCloseable {
public void close () throws Exception {
System.out.print ("Printer closed.");
}
public void printImage () {System.out.print("Print."); }
}
and this code fragment:
try (ImageScanner ir = new ImageScanner();
ImagePrinter iw = new ImagePrinter()) {
ir.scanImage();
iw.printImage();
} catch (Exception e) {
System.out.print(e.getMessage());
}
What is the result?

  • A. Scan.Printer closed. Scanner closed. Unable to scan.
  • B. Scan.Scanner closed. Printer closed.Unable to scan.
  • C. Scan. Unable to scan.
  • D. Scan. Unable to scan. Scanner closed.
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Innovation
Highly Voted 4 years, 6 months ago
ir.scanImage() prints "Scan." then throws an exception. And because both classes are autoclosable, both close() methods will get invoked, but in reverse oreder, so iw.close() gets invoked, then ir.close() and finally, the exception message is printed so the correct answer is A Scan.Printer closed.Scanner closed.Unable to scan.
upvoted 15 times
...
asdfjhfgjuaDCV
Most Recent 4 months, 4 weeks ago
A is the correct answer...
upvoted 1 times
...
steefaand
5 months, 4 weeks ago
Selected Answer: A
Answer is A. scanImage method prints Scan and throws exception which is caught but firstly close methods of resources (in revered order) are called.
upvoted 1 times
...
r1muka5
1 year, 5 months ago
Answer is A
upvoted 1 times
...
WilsonKKerll
2 years, 4 months ago
Answer is A.
upvoted 1 times
...
adnano1234
4 years, 6 months ago
The correct answer is A
upvoted 3 times
...
Destroyer
4 years, 7 months ago
The correct answer is A
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago