File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "binding of methods" Watch "binding of methods" New topic

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

Joined: Aug 26, 2001
Posts: 7610
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

[Blog] [Blogroll] [My Reviews] My Linked In
I agree. Here's the link:
subject: binding of methods
It's not a secret anymore!