Is it possible to hide or lower access to Inherited Methods in Java?

前端 未结 8 680
死守一世寂寞
死守一世寂寞 2021-01-08 00:04

I have a class structure where I would like some methods in a base class to be accessible from classes derived directly from the base class, but not classes derived from der

8条回答
  •  星月不相逢
    2021-01-08 00:40

    When overriding a method you can only make it more public, not more private. I don't know why you use the word "general"

    Remember that, ordering from least to most restrictive:

    public

    Yes, "protected" is a less restrictive access modifier than default (when no modifier is used), so you can override a default method marking the overriding method as protected, but not do the opposite.

    Can: You can override a protected method with a public one.

    Can't: You can't override a public method with a protected one.

提交回复
热议问题