Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 188

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?

    Correct Answer: D

    The program will not compile because the close() method of the InputStreamReader class returns void, not a boolean. Therefore, trying to use it in a while condition will cause a compilation error.

Discussion
maslacOption: D

If there is not typo in the question the answer should be D because close() method is void. Exception in thread "main" java.lang.Error: Unresolved compilation problem: Type mismatch: cannot convert from void to boolean

jduarteOption: B

answer is B. ueJa The file only contains one line Course::Java. 1 time isr.skip(2); Co-u i = isr.read (); u 2 time isr.skip(2); rs-e i = isr.read (); e 3 time isr.skip(2); ::-J i = isr.read (); J i = isr.read (); e 4 time isr.skip(2); av-a i = isr.read (); a

duydnOption: D

The close() method of the InputStreamReader class returns void -> D is correct

steefaandOption: D

Answer is D. Method close returns void.

WilsonKKerllOption: D

Answer is D.

jduarteOption: B

asnwer B. Tested