I agree with J. Scott on this one - according to Sun's
Inner Classes Specification, a "static inner" class is actually called a top-level nested class, and is
not considered inner. Two of the more direct quotes are
here:
<blockquote>
The static declaration modifier was designed to give programmers a way to define class methods and class variables which pertain to a class as a whole, rather than any particular instance. They are "top-level" entities.
The static keyword may also modify the declaration of a class C within the body of a top-level class T. Its effect is to declare that C is also a top-level class. Just as a class method of T has no current instance of T in its body, C also has no current instance of T. Thus, this new usage of static is not arbitrary.
As opposed to top-level classes (whether nested or not), inner classes cannot declare any static members at all. To create a class variable for an inner class, the programmer must place the desired variable in an enclosing class.
</blockquote>
and
here:
<blockquote>
"A non-static member class, or a class defined by a block or expression, is an inner class. All other classes are top-level."</blockquote>
Unfortunately it's not the clearest spec in the world, and many Java authors seem to have chosen to ignore this terminology in favor of "static inner" classes. This includes Roberts and Heller, who were involved in writing the
SCJP exam. And even one of the official lists of objectives for the exam talks of "static inner" classes. So it's rather nebulous what the "correct" answer here is - you need to try to guess how a given question author intended the question - if an author talks about a "static inner class", he probably wants to use that terminology (unless one of the answers offered is "those don't exit").
In this particular question, it's particularly hard to tell what's on the author's mind. Since a) and b) take the time to specify that the class is "inner
to Counter", I'm inclined to think they meant "inner" as synonymous with "nested", and since they didn't mention what c)'s class might be nested inside, it's not nested in anything. So no answer would be right. On the other hand, given that at least one answer
should be right in a proper exam question, c) is the only one where I can see a loophole that allows it to be correct, so maybe it
was intended that way.
Ugh. Anyway, the question's a mess, and the terminology's a mess. I just wanted people to be aware that there are competing usages out there, and that it
can be perfectly valid to say "top-level nested class" instead of "static inner class". If Sun had written a clearer spec I'd even insist that it's always right to do so, but as it is both terms can be seen as correct.
OK, I'm off the soapbox for now.
[This message has been edited by Jim Yingst (edited February 10, 2000).]