Page 1 of 1

About Question enthuware.ocpjp.v8.2.1613 :

Posted: Mon Aug 15, 2016 8:59 pm
by dhartman0172
The question asks....

Which of the following exceptions can be declared in the throws clause of a method overriding the method:

public void perform_work( ) throws IOException {
//some code
}

one of the correct answers is an NPE.

I don't understand why this is correct. Is it because it is an unchecked exception?

I thought that if an exception of an overriding method was defined it would have to be of "Any Subclass of IOException"

Re: About Question enthuware.ocpjp.v8.2.1613 :

Posted: Mon Aug 15, 2016 9:02 pm
by admin
Yes, any method can declare any unchecked exception in its throws clause. The restriction about subclass is only for checked exceptions.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v8.2.1613 :

Posted: Tue Aug 01, 2017 8:16 am
by rolandl
So, the explanation of question/answer is not correct ....

Re: About Question enthuware.ocpjp.v8.2.1613 :

Posted: Tue Aug 01, 2017 10:25 am
by admin
Rules are applicable only to checked exceptions. The explanation is talking about additional rule imposed on an overriding method.

Unchecked exceptions have no rules. This has nothing to do with overriding.

Explanation has been added to make it more clear.

thank you for your feedback!