Java OCA OCP Practice Question 3041

Question

Consider the following code segment:

while( (ch = inputFile.read()) != VALUE) {
        outputFile.write( (char)ch );
}

Assume that inputFile is of type FileReader, and outputFile is of type FileWriter, and ch is of type int.

The method read() returns the character if successful, or VALUE if the end of the stream has been reached.

What is the correct value of this VALUE checked in the while loop for end-of-stream?.

  • a) -1
  • b) 0
  • c) 255
  • d) Integer.MAX_VALUE
  • e) Integer.MIN_VALUE


a)

Note

the read() method returns the value -1 if end-of-stream (eoS) is reached, which is checked in this while loop.




PreviousNext

Related