Java OCA OCP Practice Question 2038

Question

Given the following code, under which circumstances will the method return false?.

public static boolean test(InputStream is) throws IOException {
  int value = is.read();
  return value >= 0;
}

Select the one correct answer.

  • (a) A character of more than 8 bits was read from the input stream.
  • (b) An I/O error occurred.
  • (c) Never.
  • (d) The end of the stream was reached in the input stream.


(d)

Note

The read() method will return -1 when the end of the stream has been reached.

Normally an unsigned 8-bit int value is returned (range from 0 to 255).

I/O errors result in an IOEXception being thrown.




PreviousNext

Related