首页 > 代码库 > java类的访问级别
java类的访问级别
package-private
在官方的指导中这样描述java类的访问级别:
At the top level—public, or package-private (no explicit modifier).
At the member level—public, private, protected, or package-private (no explicit modifier).
不知道package-private是什么,于是继续往下看,看到了这样的一段话:
A class may be declared with the modifier public, in which case that class is visible to all classes everywhere. If a class has no modifier (the default, also known as package-private), it is visible only within its own package (packages are named groups of related classes — you will learn about them in a later lesson.)
大概的意思是,当一个类没有加任何访问修饰符的时候,他的默认访问级别就是package-private,即对其所在包内的其他类是可见的,对包外的类是不可见的,也就是我们常说的package级别。
Access Levels
Modifier |
Class | Package | Subclass | World |
public | Y | Y | Y | Y |
protected | Y | Y | Y | N |
no modifier | Y | Y | N | N |
private | Y | N | N | N |
java类的访问级别
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。