File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Confusion with Overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Confusion with Overriding " Watch "Confusion with Overriding " New topic
Author

Confusion with Overriding

Bhaarat Sharma
Ranch Hand

Joined: Jun 04, 2007
Posts: 96
K&B says the following on page 106
The overriding method must NOT throw checked exceptions that are new
or broader than those declared by the overridden method. For example, a
method that declares a FileNotFoundException cannot be overridden by a
method that declares a SQLException, Exception, or any other non-runtime
exception unless it's a subclass of FileNotFoundException


I have the following code which compiles fine, going against the quote above, however, if access modifiers are changed to public then it does not compile fine as stated in the quote above.

My question is that if I have private access modifiers, is the eat() method still being overridden? and if so, why don't I get an error.



omnipresent
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
Bhaarat Sharma wrote:My question is that if I have private access modifiers, is the eat() method still being overridden? and if so, why don't I get an error.

Private methods are not inherited. So the method eat in the subclass does not override anything. It is just a method that happens to have the same name as a method in the superclass.
Bhaarat Sharma
Ranch Hand

Joined: Jun 04, 2007
Posts: 96
ok that makes sense.

thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Confusion with Overriding