Why can’t we have static method in a (non-static) inner class (pre-Java 16)?

Because an instance of an inner class is implicitly associated with an instance of its outer class, it cannot define any static methods itself. Since a static nested class cannot refer directly to instance variables or methods defined in its enclosing class, it can use them only through an object reference, it’s safe to declare static methods in a static nested class.

Leave a Comment