There is nothing static (unchanging) about them. They don’t cling. They are perfectly clear, unlike radio signals garbled by static.
They are allocated when the class is loaded. static refers to a method or variable that is not attached to a particular object, but rather to the class as a whole.
static final when applied to a variable is Javanese for "constant". All static methods are automatically final. It is not strictly speaking an error to mark them final, but it is redundant and considered bad form.
static methods work without any this object. static methods are limited to calling other static methods in the class and to using only static variables. They can call instance methods only if they use their own object references -- not rely on this .
static methods and variable are in a sense inherited, but not in the same strong sense that instance variables and methods are. You can refer to Dog.bark() as Dalmatian.bark() if no one has written a Dalmatian.bark(). However, if you use Dog.bark() you always get the Dog version and if you say Dalmatian.bark() you always get the Dalmatian version.
Newbies tend to overuse static variables. Consider what would happen if your code were used by several threads simulaneously. With shared static variable they would trip over each other. With local and instance variables they often would not, even without any special sychronisation. Sometimes, of course, you do need the globalness of static variables, but don’t use it where it would make more sense to create a object to track each chain of calculation.
![]() |
and suggestions to improve this page to Roedy Green : | ||
| Canadian Mind Products | |||
| mindprod.com IP:[65.110.21.43] | |||
| Your face IP:[38.103.63.17] | The information on this page is for non-military use only. | ||
| You are visitor number 187,425. | Military use includes use by defence contractors. | ||
| You can get a fresh copy of this page from: | or possibly from your local J: drive (Java virtual drive/Mindprod website mirror) | ||
| http://mindprod.com/jgloss/static.html | J:\mindprod\jgloss\static.html | ||