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

classinner-classesjavastatic

Why can't we have static method in a non-static inner class?

If I make the inner class static it works. Why?

Best Solution

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.