aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes binding of methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "binding of methods" Watch "binding of methods" New topic
Author

binding of methods

Rick Reumann
Ranch Hand

Joined: Apr 03, 2001
Posts: 281
I apologize because I know this topic has been brought up before and I should click on all the links that come up on it when I do a search. I have some last minute review stuff I have to go over before I take this exam tomorrow.
I'm curious about the code below:

I understand that if method1 in Parent was changed to public that the child's method1 would end up being called when this was run. I'm just not sure exactly why making the method private in parent messes things up. I understand that private methods aren't inherited but why should that matter if Child has it's own version of method1. I know it has something to do with when things are bound etc., but I'm still confused on this topic. Any light much appreciated.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Rick,
when you declare a method private, first it is not inherited and second it cannot be overridden. That means that you cannot "specialize" your private method in a subclass, or in clear, you cannot use polymorphism. If you invoke method1 (which is private) from within the Parent class, then method1 in Parent will be invoked because it cannot be found (read overridden) somewhere else since it is private.
JLS 15.12 Method Invocation Expression explains this in details.
The february newsletter about the same topic: JLS 15.12 in plain english
HIH


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: binding of methods