Creating an instance of an inner class from a static method of the outer class

A static inner class can be instantiated without the need of an instance of the outer class.

Main.java:

public class Main {
   public static void main(String args[]) {
 
      Main main = new Main();
      Main.InnerClass ic = new InnerClass();
      ic.test();
   }
 
   static class InnerClass {
      public void test() {
         System.out.println("Method test called!");
      }
   } 
}

You need an instance of the outer class to instantiate a non-static inner class. Just specify it before the new operator.

Main.java:

public class Main {
   public static void main(String args[]) {
 
      Main main = new Main();
      Main.InnerClass ic = main.new InnerClass();
      ic.test();
   }
 
   class InnerClass {
      public void test() {
         System.out.println("Method test called!");
      }
   } 
}