title: Why does Java allow us to compile a class with a name different than the file name?
body: <p>I have a file <code>Test.java</code> and the following code inside it.</p>
  
  <pre><code>public class Abcd
  {
          //some code here
  
  }
  </code></pre>
  
  <p>Now the class does not compile, but when I remove the <code>public</code> modifier , it compiles  fine. </p>
  
  <p>What is the reasoning behind Java allowing us to compile a class name that is different from the file name when it is not public.</p>
  
  <p>I know it is a newbie question, but I'm not able to find a good explanation.</p>