ProgrammingHardAccenture · Cognizant GenC

A Java method has this structure. What happens when it is compiled?

A Java method has this structure. What happens when it is compiled?
try {
    reader.read();            // throws IOException
} catch (Exception e) {
} catch (IOException e) {
}
  1. A. It compiles and the second catch handles IOException
  2. B. It compiles; both catch blocks run for an IOException
  3. C. Compile error: IOException has already been caught
  4. D. It compiles but throws an error at run time

Correct answer: C. Compile error: IOException has already been caught

A subclass handler placed after its superclass handler is unreachable, which javac reports as an error.

More OOP with C++ and Java questions

Exams that ask this topic