title: Naming Java File with Inheritance to compile
body: <p>I wanna compile java file but dont know how to name the file, since it has 2 public classes, where 1 class inherits from another. I named the file with name of Superclass, however cmd is giving me an error saying that "subclass is public, should be declared in file named Subclass.java". Can anybody help me to resolve this? thank you</p>
  
  <pre><code>    public class Superclass {
  
      public void printMethod() {
          System.out.println("Printed in Superclass.");
      }
  }
  public class Subclass extends Superclass {
  
      // overrides printMethod in Superclass
      public void printMethod() {
          super.printMethod();
          System.out.println("Printed in Subclass");
      }
      public static void main(String[] args) {
          Subclass s = new Subclass();
          s.printMethod();    
      }
  }
  </code></pre>