Java: Static vs inner class

Abhishek Sanghvi picture Abhishek Sanghvi · Aug 30, 2009 · Viewed 278.3k times · Source

What is the difference between static and non-static nested class?

Answer

Brandon E Taylor picture Brandon E Taylor · Aug 30, 2009

An inner class, by definition, cannot be static, so I am going to recast your question as "What is the difference between static and non-static nested classes?"

A non-static nested class has full access to the members of the class within which it is nested. A static nested class does not have a reference to a nesting instance, so a static nested class cannot invoke non-static methods or access non-static fields of an instance of the class within which it is nested.