title: Why can't we define main function in static inner classes?
body: <p>I have the following simple code</p>
  
  <pre><code>public class Tester {
      static class TesterChild {
          public static void main(String args[]) {
              System.out.println("Test");
          }
      }
  }
  </code></pre>
  
  <p>It compiles fine. But when I run it I get the following Error</p>
  
  <pre><code>[aniket@localhost src]$ java Tester
  Error: Could not find or load main class Tester
  </code></pre>
  
  <p>Question is why can't we define our main method in static inner class? </p>
  
  <p>Update1 :</p>
  
  <p>As specified in the answers/comments I have change the code to following</p>
  
  <pre><code>public class Tester {
      public static class TesterChild {
          public static void main(String args[]) {
              System.out.println("Test");
          }
      }
  }
  </code></pre>
  
  <p>I compiled it and it made two class files <code>Tester.class</code> and <code>Tester$TesterChild.class</code>. But still i am getting error </p>
  
  <pre><code>[aniket@localhost Desktop]$ java Tester$TesterChild
  Error: Could not find or load main class Test
  </code></pre>
  
  <p>Update 2:</p>
  
  <p>Ok now I included current directory in the classpath and executed still getting error</p>
  
  <pre><code>[aniket@localhost Desktop]$ java -cp . Tester$TesterChild
  Error: Main method not found in class Tester, please define the main method as:
     public static void main(String[] args
  </code></pre>