Java OCA OCP Practice Question 2563

Question

Consider the following code segment:

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

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

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

What is the correct value of this VAL 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