ProgrammingHardAccenture · Cognizant pattern

Parent declares void read() throws IOException. Which override in a subclass compiles?

  1. A. void read() throws Throwable
  2. B. void read() throws Exception
  3. C. void read() throws FileNotFoundException
  4. D. void read() throws IOException, SQLException

Correct answer: C. void read() throws FileNotFoundException

An overriding method may throw the same checked exceptions, narrower ones (FileNotFoundException is a subclass of IOException) or none. It may not add broader or new checked exceptions such as Exception or SQLException.

More OOP with C++ and Java questions

Exams that ask this topic