but I think your explanation is not exactly correct.
For private methods the quoted explanation is not true, private Methods are selected at compile time and not invoked dynamically, so private methods technically cannot be overridden.Now, you may think that the actual object is of class B and method is selected according to the actual object. This is true but access rights are checked at compile time.
This example shows it:
Code: Select all
public class AccessPrivateTest {
public static void main(String[] args) {
B b = new B();
b.invokePrint();
}
}
class A {
private void print() {
System.out.println("A");
}
public void invokePrint() {
print();
}
}
class B extends A {
public void print() {
System.out.println("B");
}
}
Best regards
Marcel