Re: Static Variables and JAR Files
Mark Space wrote:
Eric Sosman wrote:
Mark Space wrote:
Obviously, when you make a new class via inheritance, it gets it's
own copy of the static variable. So there will be one static for the
parent class, and one for the child class. The static is a "class
variable" and since there are two classes (parent and child) there
are two static variables.
Please predict the output of this simple demonstration, and
then test your prediction:
Well clearly I was mistaken. That's pretty frustrating too because I
looked this up before I posted, and the documentation and examples
seemed to indicate that there would be a copy of a static variable.
Even the JLS doesn't really say, it just says that non-private fields
are inherited. I'm not sure how one is supposed to determine when
documentation, including the JLS, should be taken at face value and when
one has to experiment carefully to determine what the docs actually meant.
I'm not sure what else to add, other than I'm really fuming over having
missed that.
Standardese can sometimes be as opaque as a meter of mud.
Perhaps the thing to remember here is that "inherit" does not
mean "make a copy of." The subclass "inherits" the accessible
members of its superclasses, but that doesn't mean it makes
its own local copies of them. They continue to "reside in" or
"belong to" the superclasses, although they can be accessed
through the subclass.
--
Eric.Sosman@sun.com