Override “private” method in java

后端 未结 5 1073
小蘑菇
小蘑菇 2020-11-27 16:18

There something ambiguous about this idea and I need some clarifications.

My problem is when using this code:

public class B {

    private void don(         


        
5条回答
  •  迷失自我
    2020-11-27 16:50

    You can't override a private method, but you can introduce one in a derived class without a problem. The derive class can not access the private method on the ancestor.

    Since t is a on object of type B, calling don() method will invoque the method defined at B. It doesn't even know that there is a method named also don() at class A

提交回复
热议问题