Submitted by ljjy23 on Sun, 08/07/2011 - 03:25.
while reading Thinking in java, I get confused when I saw the example below(the example is in page 290, Chapter polymorphism):
public class PrivateOverride{
private void f(){print("private f()");}
public static void main(){
PrivateOverride po = new Derived();
po.f();
}
}
class Derived extends PrivateOverride{
public void f(){print("public f()")}
}
the result is private f();
I have two confusions:
1: the author said that when we inherit, we automatically get all the fields and mehtods in the base class(page 241 Inheritence syntax),so in the case above, does class Derived has a private mehtod called f()?
2: what underlying mechanism makes it possible for a derived class reference to invoke a method defined in the base class?