Java OCA OCP Practice Question 35

Question

This question involves IOException, AWTException, and EOFException.

They are all checked exception types.

IOException and AWTException extend Exception.

EOFException extends IOException.

Suppose class X contains the following method:

void doSomething() throws IOException{ ... } 

Which of the following methods may appear in class Y, which extends X?

  • A. void doSomething() { ... }
  • B. void doSomething() throws AWTException { ... }
  • C. void doSomething() throws EOFException { ... }
  • D. void doSomething() throws IOException, EOFException { ... }


A, C, D.

Note

An overriding method may throw an unlimited number of exception types, if all types are

  • the same as, or
  • are descended from, the types that appear in the overridden version's declared list of thrown exception types.



PreviousNext

Related