您的位置:首页 > 其它

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

2013-12-23 22:00 387 查看
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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐