Java SE 8 Programmer II — Question 102

Given that course.txt is accessible and contains:

Course : : Java -
and given the code fragment:
public static void main (String[ ] args) {
int i;
char c;
try (FileInputStream fis = new FileInputStream ("course.txt");
InputStreamReader isr = new InputStreamReader(fis);) {
while (!isr.close()) { //line n1
isr.skip(2);
i = isr.read ();
c = (char) i;
System.out.print(c);
}
} catch (Exception e) {
e.printStackTrace();
}
}
What is the result?

Answer options

Correct answer: D

Explanation

The correct answer is D because the condition in the while loop incorrectly attempts to call isr.close(), which returns void and cannot be evaluated as a boolean. Options A, B, and C are incorrect since the program will not execute successfully due to the compilation error at line n1.