As a side note, given that your main question has been answered - often people will declare inner classes, as in your example above, without thinking about whether they can be static inner classes.
In my experience, the vast majority of (non-anonymous) inner classes can be static because they do not need to access members of an instance of their parent class. Declaring the inner class as static in this case is more efficient (since the runtime does not require defining a new class for each parent instance), it is less confusing (with new TestClass().new InnerClass().getClass() != new TestClass().new InnerClass().getClass() ) and it is easier to create if you do not have a suitable instance of TestClass .
So, if this applies to you, you can (and perhaps should) declare you an inner class:
public class TestClass { public static class InnerClass { } }
and then you can just create it as new TestClass.InnerClass() .
(If you need to access member fields from InnerClass, then just ignore it all!)
Andrzej doyle
source share