Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


What exception is caught in the FormattedMemoryInput example?

  1. IOException

  2. EOFException

  3. FileNotFoundException

  4. DataFormatException

The correct answer is: EOFException

The FormattedMemoryInput example is an example of reading input as a stream of formatted data from a StringReader object using the read() method. In this example, the data is read one character at a time and is converted into an int value that represents the character. This process continues until the end of the string is reached, at which point an EOFException is thrown to indicate the end of the input has been reached. The other options, IOException, FileNotFoundException, and DataFormatException, do not accurately describe the type of exception that is caught in this example. IOException is a general exception for all input/output related errors, FileNotFoundException is thrown when an attempt to open a file has failed, and DataFormatException is thrown when there is an invalid format for the data being read. Since none of these exceptions are caught in the FormattedMemoryInput example, they are not the correct answer.