1Z0-809 · Question #112
Scan.Printer file = new Scan.Printer(); Scan.Scanner scanner = new Scan.Scanner(file); scanner.scan(); What is the result?
The correct answer is A. Scan.Printer closed. Scanner closed. Unable to scan. Option A is correct because Scan.Scanner wraps Scan.Printer as its underlying resource, so when scan() is invoked and the operation fails, the Scanner's close logic first releases the inner resource it owns (Printer) before closing itself - producing "Printer closed." then…
Question
Options
- AScan.Printer closed. Scanner closed. Unable to scan.
- BScan.Scanner closed. Unable to scan.
- CScan.Unable to scan.
- DScan. Unable to scan. Printer closed.
How the community answered
(49 responses)- A76% (37)
- B8% (4)
- C4% (2)
- D12% (6)
Explanation
Option A is correct because Scan.Scanner wraps Scan.Printer as its underlying resource, so when scan() is invoked and the operation fails, the Scanner's close logic first releases the inner resource it owns (Printer) before closing itself - producing "Printer closed." then "Scanner closed." and finally "Unable to scan." Option B is wrong because it skips the Printer closing entirely, incorrectly suggesting the Scanner closes independently without cleaning up its wrapped resource. Option C is wrong because it omits both closing messages, as if no resource cleanup occurred at all. Option D is wrong because it reverses the closing sequence and drops the "Scanner closed." message, misrepresenting both the order and completeness of cleanup.
Memory tip: Think of it like nested containers - the outer wrapper (Scanner) owns the inner resource (Printer), so cleanup always flows inside-out: Printer closes first (inside Scanner's close), then Scanner closes, then failure is reported. Wrapper classes always clean up what they wrap before cleaning up themselves.
Community Discussion
No community discussion yet for this question.