When a class has no explicitly declared constructor, the compiler inserts a default zero-argument constructor which has the 与类相同的访问说明符. (JLS 8.8.9) The default constructor is commonly misstated as always being public, but 在极少数情况下 that's not equivalent.
在枚举中,构造函数默认为 二等兵。实际上,枚举构造函数 必须的是私有的,将它们指定为 public 或 protected 是错误的。枚举常数始终是 public,并且不允许任何访问说明符。默认情况下,枚举的其他成员是 私人包裹。(JLS 8.9)
In interfaces and annotation types, all members (again, that means fields, methods, and nested type declarations) are 公众人士 by default. Indeed, members of interfaces and annotation types 必须的 be public, and it is an error to specify them as private or protected. (JLS §9.3 to 9.5)
Bill Venners : Java 有四个访问级别
一直想知道使包访问默认是否方便
因为 C + + 的人已经知道的三个关键词
是私人的,受保护的,公共的。或者如果你有一些特别的
您认为包访问应该是默认的原因。
James Gosling: A package is generally a set of things that are kind of
所以一般来说,我可以做两件事情中的一件。
One was force you always to put in a keyword that gives you the
或者我可以有一个默认值。然后问题是,
什么是合理的违约? 我倾向于选择最小的违约
危险的东西。
因此,公开违约将是一件非常糟糕的事情。
私有可能是一件坏事,使违约,如果
只是因为人们实际上不经常编写私有方法。
和受保护的一样,看着一堆代码
我有,我决定,最常见的东西,是相当安全的
C + + 没有这个关键字,因为
他们没有包的概念。
但是我喜欢它,而不是朋友的概念,因为与朋友
你得列举出你所有的朋友
向包中添加一个新类,那么通常最终必须
go to all of the classes in that package and update their friends,
我一直觉得这是个大麻烦。
但是好友列表本身会导致一些版本问题
所以就有了友好课堂的概念
我把它设置为默认值——我会解决这个问题,那么应该怎么做呢
the keyword be?
For a while there actually was a friendly keyword. But because all the
有的是 P 开头,有的是“友好”有个“ PH”但那是
只在里面待了一天。