Override “private” method in java

后端 未结 5 1081
小蘑菇
小蘑菇 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 17:00

    is this because the main function is in the same class as the method "don"

    No, it's because A's don() is unrelated to B's don() method, in spite of having the same name and argument list. private methods are hidden inside their class. They cannot be invoked directly by outside callers, such as main method in your case, because they are encapsulated inside the class. They do not participate in method overrides.

提交回复
热议问题