class Base {
private void SayHello(){ //PRIVATE
System.out.println("Hello from Base");
}
}
class Derived extends Base {
public void sayHello(){ //PUBLIC
System.out.println("Hello from Derived");
}
}
public class TestHello{
public static void main(String[] args) {
Derived d = new Derived();
Base b = d;
d.sayHello(); //works as expected
b.sayHello(); //Why does this not work?
}
}
I want to understand: is the private sayHello from base class visible to the derived class? or is it a redefinition? And why does the call to the derived sayHello from the base pointer does not work? I mean, if it were public (in Base), then the sayHello from the derived class would have been called. So, what I can not understand is that if it has to call the public sayHello from the derived class, then why look at the access modifier from the base class?
Also, if you can point me to some concise resource that will help me understand this in more depth, I'd really appreciate this. Thanks!