I have confusion about using private methods in inheritance, for example:
public class A {
private void say(int number){
System.out.print("A:"+number);
}
}
public class B extends A{
public void say(int number){
System.out.print("Over:"+number);
}
}
public class Tester {
public static void main(String[] args) {
A a=new B();
a.say(12);
}
}
Based on the codes above, I am confused about the inheritance of private method, is the private method inherited from class A
to B
? Or the say methods in both classes are totally unrelated? As the code has error when it is running in main() method, it seems like class B
cannot invoke the private method from class A
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…