Java: protected access across packages

后端 未结 4 1612
我在风中等你
我在风中等你 2020-12-14 11:20

I would like to understand what\'s happening in the example below (where a protected member is being accessed from outside the package through a subclass).

I know fo

4条回答
  •  北海茫月
    2020-12-14 11:44

    I believe you've answered your own question; UsesExtendedClass does not inherit from ProtectedClass, and -- by definition -- "protected" members are accessible only in the class in which they are declared / defined or in a class that inherits from the one in which they are declared or defined.

提交回复
热议问题