Page 1 of 1

About Question enthuware.ocpjp.v7.2.1128 :

Posted: Tue Apr 21, 2015 3:31 pm
by costin1989
Overriding method cannot throw any exceptions that are not thrown by the overridden method.

and your answer is False.

so you mean the overriding method can throw any exceptions that are not thrown by the overridden method.

This code is valid?

class A{
void m1() throws IOException{}
}

class B extends A{
void m1() throws Exception {}
}

Thanks!

Re: About Question enthuware.ocpjp.v7.2.1128 :

Posted: Tue Apr 21, 2015 7:40 pm
by admin
No, if you want to get into the grammatical sense, the opposite of that statement would be, "Overriding method can throw some exceptions that are not thrown by the overridden method". The "some" would include subclasses of those exceptions and unchecked exceptions.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v7.2.1128 :

Posted: Wed Jan 27, 2016 2:41 pm
by toolforger
The "some" would include subclasses of those exceptions
Well, an exception of a subclass is also an exception of the superclass, so that's not really true.

Agreed on unchecked exceptions.