Static Inner Classes

Syntex Of Static Inner Class
[access-specifier] class OuterClass {
    public static class StaticInnerClass {
        code...
    }
    code...
}
  • Static members of the outer class are visible to the static inner class, whatever their access level be.
  • Non-static members of the outer class are not available, because there is not instance of the outer class.
  • An inner class may not have static members unless the inner class is itself marked as static.
  • Static inner classes don't require outer classes instance.
  • A static inner class is just like any other inner class, but it does not have the reference to its outer class object that generated it.

Static Inner Class Example
class Outer {
    static int x = 100;
    
	static class Inner {
        static void show() {
            System.out.println("Inside Static Inner Class Show "+x);
        }
    }
}
public class InnerDemo {
    
    public static void main(String[] args) {
        Outer.Inner.show();
    }
}
Output
Inside Static Inner Class Show 100