Why is there no sub-class visibility modifier in Java?

前端 未结 3 1955
一整个雨季
一整个雨季 2020-12-13 01:52

On more than one occasion I have found myself desiring a variable visibility that is not possible in Java. I wanted certain members to be visible within their own class and

3条回答
  •  旧时难觅i
    2020-12-13 02:14

    You should put your class in a package of it's own and mark the member(instance variable or method) as protected. This way no other classes, except the subclasses can access that member which you market as protected. You will end up with one class in one package, if you desperately want only subclasses to access that protected member.

提交回复
热议问题