Java有私有、受保护和公共访问修饰符。你能解释一下这些修饰符的可访问性范围吗?
如何访问不同包中的受保护成员?
发布于 2013-04-18 12:45:57
为了更好地理解,您需要查看以下内容
Access Modifiers
Same Class Same Package Subclass Other packages
public Y Y Y Y
protected Y Y Y N
no access modifier Y Y N N
private Y N N N这里最重要的区别是Default和protected之间的区别。
默认值:永远不能在包之外访问
Protected:仅当且仅当类是子类时,才能在包外部访问。
编辑:作为您的问题的答案也与You can access the protected member by make your class a sub class of the class , in which protected member is defined相同
https://stackoverflow.com/questions/16074621
复制相似问题