Page 1 of 1

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

Posted: Thu Dec 22, 2016 9:24 pm
by sulakshana
The return type can also be a subclass of the original method's return type.....
checked and unchecked exceptions...
I did not got this 2 statements ... pls explain with details...thanx......

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

Posted: Thu Dec 22, 2016 10:39 pm
by admin
1. If the return type of a method in the base class is A, then the return type of the overriding method in a subclass can be A or any subclass of A. This is explained nicely here: http://www.javatpoint.com/covariant-return-type

2. Not sure what are you asking about checked and unchecked exception.

HTH,
Paul.

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

Posted: Mon Nov 20, 2017 8:05 am
by Arold Aroldson
Why this option is incorrect? "An overriding method can declare that it throws a wider spectrum of checked exceptions than the method it is overriding."?
Overriding method can declare that it throws any amount of exceptions, isn't it?

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

Posted: Mon Nov 20, 2017 9:19 am
by admin
No, the overriding method can only throw the same or narrower set of checked exceptions than the superclass's method.

Which book are you following?

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

Posted: Mon Nov 20, 2017 11:16 pm
by Arold Aroldson
sorry, i didn't know that unchecked exceptions were not considered

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

Posted: Mon Nov 20, 2017 11:23 pm
by admin
Unchecked exceptions have no rules. That is why they are called "unchecked". They are not checked for any rules :)

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

Posted: Thu Jan 07, 2021 2:50 am
by Denyo1986
Question:
Private methods cannot be overridden in subclasses.

Correct Answer:
not true / unchecked


>>>>> I think this is wrong. Cause when you read YOUR OWN explanation:
"Only methods that are inherited can be overridden and private methods are not inherited."

Only methods that are inherited can be overridden. Privat methods are not inherited. So private methods THEREFORE cannot be overridden in subclasses. It is the logical conclusion of your own explanation.
This question is highly ambiguous and should be changed in my opinion.

Very curious to hear your response to this.

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

Posted: Thu Jan 07, 2021 3:08 am
by admin
It is indeed marked as correct! See attached screenshot (option 1 and 5 are in green).
test.png
test.png (50.85 KiB) Viewed 4304 times

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

Posted: Thu Jan 07, 2021 3:11 am
by Denyo1986
Wow, such a quick reply. That is great. Thanks a lot.
And I am afraid you are right....I confused the highlighting.
My apologies.

Have a nice day

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

Posted: Tue Oct 31, 2023 11:44 am
by Tester
The overriding method may opt not to declare any throws clause even if the original method has a throws clause.
Sorry, what does it mean "opt" here?

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

Posted: Tue Oct 31, 2023 11:50 am
by admin