protected修饰的成员属性和方法的可见范围:子类或同一个包中的类

来源:互联网 发布:淘宝店铺首页图片尺寸 编辑:程序博客网 时间:2024/06/06 03:46
If a method or instance variable is modified by protected (rather than public or
private), then it can be accessed by name inside its own class definition, it can be
accessed by name inside any class derived from it, and it can also be accessed by name
in the definition of any class in the same package (even if the class in the same package
is not derived from it). However, the protected method or instance variable cannot be
accessed by name in any other classes. Thus, if an instance variable is marked protected

in the class Parent and the class Child is derived from the class Parent, then the

instance variable can be accessed by name inside any method definition in the class
Child. However, in a class that is not in the same package as Parent and is not derived
from Parent, it is as if the protected instance variable were private.
0 0
原创粉丝点击