That is true. Only a static inner class may have static members.
Ivor Horton<br />Author of the Beginning Java Series including the new <a href="http://www.amazon.com/exec/obidos/ASIN/1861005695/ref=ase_electricporkchop" target="_blank" rel="nofollow">Beginning Java 2 SDK 1.4 Edition</a>
Dave, you are quite correct. The exception for a non-static inner class is a static field that is declared as final and initialized with a constant or a constant expression. No other kind of static members are permitted.
I think it's easiest to think of it as inner classes can't have static members (unless of course they are compile time constants -final members). Not to bring up a maybe more advanced topic in a beginner forum but as far as I can recall a static class inside of another class really isn't an "inner" class per se since it's not tied to an instance of that outer class. It's just a top level class that happens to reside within another class. I'm probably just making the topic more confusing so I should shut up but it might help to think of static classes all by themselves - whether they reside inside of another class or not - and then think of other non-static classes inside of another class as true inner class.
Joined: Jul 18, 2001
Thanks you guys. I wasn't aware of that exception until I got a wrong answer on a Jqplus exam. I see they were right.
Joined: Mar 22, 2002
No definitely should not shut up Rick - you are quite right. The precise terminology used by Gosling is that a static class defined inside another class is called a static nested class. A static nested class is indeed just like a top-level class. Nesting inside another class only serves to qualify the class name by the outer class name. A non-static nested class is called an inner class. This is quite a different concept since objects of the inner class type are always associated with instances of the outer class type.