Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Inheritence problem(a demo form Thing in java)



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?