File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confusion with Overriding

 
Bhaarat Sharma
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
dennis deems
Ranch Hand
Posts: 808
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok that makes sense.

thanks
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic