wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes is it a error in kb6  book page no. 121? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "is it a error in kb6  book page no. 121?" Watch "is it a error in kb6  book page no. 121?" New topic
Author

is it a error in kb6 book page no. 121?

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

please consider the following paragraph from kb6 book page 121 stated as bullet point 3rd

Declare no checked exceptions on implementation methods other than
those declared by the interface method, or subclasses of those declared by
the interface method.



it says that if an interface declare say a checked exception , the implementation method should not declare the subclass of those checked exception. i tried to verify it but i think it is incorrect since i was able to declare checked exception that were subclass of the one declared in interface method contract . or i may be interpreting the book wrongly. please help ? below is my program





saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

May it'll help.


Tell the difficulties that i am difficult.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

gurpeet singh wrote:

Declare no checked exceptions on implementation methods other than
those declared by the interface method, or subclasses of those declared by
the interface method.



From your quote :
or subclasses of those declared by the interface method. that is why you did not get any exception. i think you are reading the overriding rules .

overridden method(method at subclass) may or may not declare the same exception what declared in super class but you can not declare the super class[ancestor] of the exception declared in super class's method.
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

thanks alot Saloni
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

Seetharaman Venkatasamy wrote:
gurpeet singh wrote:

Declare no checked exceptions on implementation methods other than
those declared by the interface method, or subclasses of those declared by
the interface method.



From your quote :
or subclasses of those declared by the interface method. that is why you did not get any exception. i think you are reading the overriding rules .

overridden method(method at subclass) may or may not declare the same exception what declared in super class but you can not declare the super class[ancestor] of the exception declared in super class's method.


thanks for reply Seetharaman. but i'm not reading the rules for overidding. i have given kb6 book page no . the topic is rules of the non-abstract implementation class implementing an interface. following are the complete rules given in the book:

Provide concrete (nonabstract) implementations for all methods from the
declared interface.
■ Follow all the rules for legal overrides.
■ Declare no checked exceptions on implementation methods other than
those declared by the interface method, or subclasses of those declared by
the interface method.
■ Maintain the signature of the interface method, and maintain the same
return type (or a subtype). (But it does not have to declare the exceptions
declared in the interface method declaration.)


i'm having doubt on the third bulleted point.
Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
The third bulleted point says if the method declaration in the interface declare a checked exception, its overriding method does not need to declare the checked exception or its subclass exception.
For example in the Boucneable interface,

In the Ball class, the Bounce method may not declare any thrown checked exception:
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

a note:but remember all these *throws* rules are for *only to checked* exception. because it is not advisable to throws RuntimeException
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774

Declare no checked exceptions on implementation methods other than
those declared by the interface method, or subclasses of those declared by
the interface method.


There is no error in this paragraph gurpreet. It simply says that the overriding method should not declare any checked
exception which are not defined in the interface contract or you can declare the subclasses of those exceptions which are
specifically declared by the contract.
HTH,


Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
 
Consider Paul's rocket mass heater.
 
subject: is it a error in kb6 book page no. 121?
 
Similar Threads
Polymorphic behavior provided by inheritance programming assignment
basic interface doubt
basic interface doubt
runtime error
Checked exception and interface.