Page 1 of 1

About Question enthuware.ocajp.i.v8.2.945 :

Posted: Wed Feb 24, 2016 6:07 am
by goncaloncpinto
On this statement:

An overriding method cannot exhibit behavior that contradicts the declaration of the original method. An overriding method therefore cannot return a different type (except a subtype) or throw a wider spectrum of exceptions than the original method in the superclass.

I think the part in red is wrong, you can throw any unchecked exception or error (not a good practice though) from the overriding method.

Am I right?

Re: About Question enthuware.ocajp.i.v8.2.945 :

Posted: Wed Feb 24, 2016 7:13 pm
by admin
Unchecked exceptions i.e. RuntimeExceptions and Errors are not required to be declared at all. So, yes, they can be thrown by any method anytime but that is not really relevant here.

We will add this point to the explanation to make it clear.
Thank you for your feedback.
Paul.

Re: About Question enthuware.ocajp.i.v8.2.945 :

Posted: Thu Feb 25, 2016 9:17 am
by goncaloncpinto
I was not very clear on my comment too. The text in red is not wrong, i wanted to say it can be better making it more clear. :)

Thanks.