A static field or member is maintained once in memory and used by all instances of that class. One way to imagine using this is to think of an instance counter. You could increment it every time an object gets made, and each object would then "know" how many total instances had been created. A static method can be invoked without ever making an instance of the class that contains it. Best straightforward example: all the methods in the Math class. You don't really need a Math object for anything, so why create one just to make use of its functions ? (You can't make Math objects, anyway, but that's because it's final class). ------------------ Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
Make visible what, without you, might perhaps never have been seen. - Robert Bresson
Stanley Tan
Ranch Hand
Joined: May 17, 2001
Posts: 243
posted
0
For example, imagine you have 20 people with different hair colors. If the hair color were static and one person changed his hair color to blue, then you would have 20 people with blue hair .
Richard Boren
Ranch Hand
Joined: Mar 01, 2001
Posts: 233
posted
0
Originally posted by Michael Ernest: ... (You can't make Math objects, anyway, but that's because it's final class).
The reason you cannot instantiate the Math class is becuase it has a private constructor (private Math() {}), not because the class is final. When a class is made final it is saying it cannot be extended which has nothing to do with it being instantiated.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.