Can I override a private method in Java?

前端 未结 10 1236
天涯浪人
天涯浪人 2020-11-29 08:26

I know I can use reflection to invoke a private method, and to get or set the value of a private variable, but I want to override a method.

public class Supe         


        
10条回答
  •  被撕碎了的回忆
    2020-11-29 09:27

    You can't override a private method because no other class, including a derived class, can tell that it exists. It's private.

    Private methods are implicitly final.

    On a related note, a subclass can declare a field or method with the same name as a private field or method in a super class, because from the subclass's point of view, these members do not exist. There's no special relationship between these members.

提交回复
热议问题