title: Java: Multiple class declarations in one file
body: <p>In Java, you can define multiple top level classes in a single file, providing that at most one of these is public (see <a href="http://docs.oracle.com/javase/specs/jls/se8/html/jls-7.html#jls-7.6" rel="noreferrer">JLS §7.6</a>).  See below for example.</p>
  
  <ol>
  <li><p>Is there a tidy name for this technique (analogous to <code>inner</code>, <code>nested</code>, <code>anonymous</code>)?</p></li>
  <li><p>The JLS says the system <strong>may</strong> enforce the restriction that these secondary classes can't be <code>referred to by code in other compilation units of the package</code>, e.g., they can't be treated as package-private.  Is that really something that changes between Java implementations?</p></li>
  </ol>
  
  <p>e.g., PublicClass.java:</p>
  
  <pre><code>package com.example.multiple;
  
  public class PublicClass {
      PrivateImpl impl = new PrivateImpl();
  }
  
  class PrivateImpl {
      int implementationData;
  }
  </code></pre>