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

Moderator: admin

Post Reply
sulakshana
Posts: 14
Joined: Thu Dec 22, 2016 8:55 pm
Contact:

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

Post by sulakshana » Thu Dec 22, 2016 9:24 pm

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......

admin
Site Admin
Posts: 8543
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Thu Dec 22, 2016 10:39 pm

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.
If you like our products and services, please help us by posting your review here.

Arold Aroldson
Posts: 21
Joined: Mon Nov 20, 2017 8:00 am
Contact:

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

Post by Arold Aroldson » Mon Nov 20, 2017 8:05 am

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?

admin
Site Admin
Posts: 8543
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Mon Nov 20, 2017 9:19 am

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?
If you like our products and services, please help us by posting your review here.

Arold Aroldson
Posts: 21
Joined: Mon Nov 20, 2017 8:00 am
Contact:

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

Post by Arold Aroldson » Mon Nov 20, 2017 11:16 pm

sorry, i didn't know that unchecked exceptions were not considered

admin
Site Admin
Posts: 8543
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Mon Nov 20, 2017 11:23 pm

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests