Q1: Why are static members not allowed to be declared in inner classes? Q2: Why are static members allowed to be inherited by inner classes if they are not allowed to be declared in inner classes? [ April 25, 2003: Message edited by: Marlene Miller ]
Howdy A static member has to be accessible *without* necessarily having an instance of the class with the static member. But... an inner class (non-static nested class) has no meaning in life until it's instantiated. But the inner class can *inherit* them, because once the inner class is instantiated, it has access to everything in the enclosing class instance to which the inner class instance is tied. So to be a truly good 'helper' to the enclosing class *instance* (which is the way I think about inner class objects-- as helpers to the outer object), it would need access to everything, statics included. But again, since an inner class has no meaning until its instantiated, there'd be no point in putting statics in it. Does that make any sense? I've never actually thought about this, although it seems like a pretty significant point! cheers, Kathy
Originally posted by Jose Botella: Don't you like Kathy's one?
Yes, I do like Kathy's post but I started to write it before Kathy posted her's. Then I deleted mine before you posted yours. I actually started to write an explanation similar to Kathy's but then I backed away from it because I thought that I might be starting a long debate on the design choices for Java.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Joined: Jul 03, 2001
It happens to me all the time. [ April 25, 2003: Message edited by: Jose Botella ]
Joined: Mar 05, 2003
Thank you Kathy. I understand what you mean by a helper object. That makes sense. Suppose several inner class objects wanted to share some class data, such as an identifier or an ArrayList.