1Z0-809 · Question #50
Given that course.txt is accessible and contains: Course : Java and given the code fragment: public static void main (String[ ] args) { char i; try (FileInputStream fis = new FileInputStream…
The correct answer is D. A compilation error occurs at line n1. Option D is correct because InputStreamReader.close() has a return type of void - it doesn't return a value at all - so applying the logical NOT operator (!) to a void result is a type mismatch that the compiler rejects at line n1. Options A and B are wrong because they assume…
Question
Options
- Aur::va
- BueJa
- CThe program prints nothing.
- DA compilation error occurs at line n1.
How the community answered
(32 responses)- A6% (2)
- B3% (1)
- C13% (4)
- D78% (25)
Explanation
Option D is correct because InputStreamReader.close() has a return type of void - it doesn't return a value at all - so applying the logical NOT operator (!) to a void result is a type mismatch that the compiler rejects at line n1. Options A and B are wrong because they assume the code reaches runtime and produces output by tracing the skip(2)/read() pattern, but a program that fails to compile never runs. Option C is wrong for the same reason - "prints nothing" implies successful execution with no output, whereas a compilation error means execution never starts. Memory tip: Treat close() like println() - both return void, and you'd never write if (!System.out.println(...)), so similarly never use close() as a loop condition; use a separate boolean flag or restructure with read() as the condition instead.
Community Discussion
No community discussion yet for this question.