About Question enthuware.ocajp.i.v8.2.945 :
Moderator: admin
-
- Posts: 14
- Joined: Thu Dec 22, 2016 8:55 pm
- Contact:
About Question enthuware.ocajp.i.v8.2.945 :
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......
checked and unchecked exceptions...
I did not got this 2 statements ... pls explain with details...thanx......
-
- Site Admin
- Posts: 10064
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.945 :
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.
2. Not sure what are you asking about checked and unchecked exception.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 21
- Joined: Mon Nov 20, 2017 8:00 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.945 :
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?
Overriding method can declare that it throws any amount of exceptions, isn't it?
-
- Site Admin
- Posts: 10064
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.945 :
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?
Which book are you following?
If you like our products and services, please help us by posting your review here.
-
- Posts: 21
- Joined: Mon Nov 20, 2017 8:00 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.945 :
sorry, i didn't know that unchecked exceptions were not considered
-
- Site Admin
- Posts: 10064
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.945 :
Unchecked exceptions have no rules. That is why they are called "unchecked". They are not checked for any rules
If you like our products and services, please help us by posting your review here.
-
- Posts: 38
- Joined: Thu Jan 07, 2021 2:47 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.945 :
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.
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.
-
- Site Admin
- Posts: 10064
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.945 :
It is indeed marked as correct! See attached screenshot (option 1 and 5 are in green).
If you like our products and services, please help us by posting your review here.
-
- Posts: 38
- Joined: Thu Jan 07, 2021 2:47 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.945 :
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
And I am afraid you are right....I confused the highlighting.
My apologies.
Have a nice day
-
- Posts: 34
- Joined: Mon Oct 30, 2023 11:55 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.945 :
Sorry, what does it mean "opt" here?The overriding method may opt not to declare any throws clause even if the original method has a throws clause.
-
- Site Admin
- Posts: 10064
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.945 :
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 93 guests