class A {
public void talk(){
this.sayIt();
}
private void sayIt(){
System.out.println("class A says...");
}
}
class B extends A {
private void sayIt(){
System.out.println("class B says...");
}
}
Test class, main method:
B b = new B();
b.talk()
//output
class A says...
I cannot get this since:
Class B inherits from class A, the public member and cannot see/inherit the private function. So in class B, we could call talk(). //since it is inherited by the parent class.
Now, in the talk() method, there is a call to sayIt() since sayIt() is defined in class B,
I would expect a call to B.sayIt() to be made when this.sayIt() is executed.
Doesn't "this" refer to the class B?
Please Explain.
talkmethod is not in classB.