当前位置: 技术问答>java相关
关于protected modifier的一个疑问
来源: 互联网 发布时间:2015-03-14
本文导语: 我不太明白这句话 But a subclass in another package can access the protected members in the super-class via only the references of subclass or its subclasses. A subclass in the same package doesn’t have this restriction. This ensures that ...
我不太明白这句话
But a subclass in another package can access the protected members in the super-class via only the references of subclass or its subclasses.
A subclass in the same package doesn’t have this restriction. This ensures that classes from other packages are accessing only the members that are part of their inheritance hierarchy.
哪位能写个例子解释解释吗?
But a subclass in another package can access the protected members in the super-class via only the references of subclass or its subclasses.
A subclass in the same package doesn’t have this restriction. This ensures that classes from other packages are accessing only the members that are part of their inheritance hierarchy.
哪位能写个例子解释解释吗?
|
这是java中类的限定词作用范围的规定
同一个类 同一个包 不同包中的子类 不同包中的非子类
private OK
default OK OK
protected OK OK OK
public OK OK OK OK
举例比较麻烦,你看看书吧,比如thinking in java,里面有!
同一个类 同一个包 不同包中的子类 不同包中的非子类
private OK
default OK OK
protected OK OK OK
public OK OK OK OK
举例比较麻烦,你看看书吧,比如thinking in java,里面有!