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

Rahul Garg picture Rahul Garg · Jun 10, 2009 · Viewed 69.5k times · Source

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

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

Answer

Bill the Lizard picture Bill the Lizard · Jun 10, 2009

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.