Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From the <a href="http://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.1.1" rel="noreferrer">Java Language specification</a>:</p> <blockquote> <p>The access modifiers protected and private pertain only to member classes within a directly enclosing class declaration</p> </blockquote> <p>So yes, the private and the protected modifiers are not allowed for top level class declarations.</p> <p><strong>Top-level</strong> classes may be public or not, while <code>private</code> and <code>protected</code> are not allowed. If the class is declared public, then it can be referred to from any package. Otherwise it can only be referred to from the same package (namespace).</p> <p>A private top level class wouldn't make much sense because it couldn't be referred to from any class. It would be unusable by definition. <code>private</code> is OK for member classes to make a class referable to only it's enclosing class.</p> <p>A protected member class can be referred to from (1) any class of the same package and from (2) any subclass of the enclosing class. Mapping this concept to top level classes is difficult. The first case is covered by top level class with no access modifiers. The second case is not applicable for top level classes, because there is no enclosing class or something else from a different package with a special relation to this class (like a subclass). Because of this I think, <code>protected</code> is not allowed because it's underlying concept is not applicable for top level classes.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload