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

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

Prepare for your Java exam with our ultimate quiz based on 'Thinking in Java'. Engage with expertly crafted questions that enhance your learning process. Perfect for Java enthusiasts looking to solidify their knowledge!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

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.