Reputation: 135
What is the reason behind using the word "static" in "static variables" or "static methods"?
I'm not asking for the definition of "static", just asking why it is called so.
Upvotes: 5
Views: 2007
Reputation: 13686
In Head First Java, there is a nice explanation of static. Static means stable not changing thats obvious from meaning and its quite obvious that it does not change.
Static mean sharing in Java. There is a nice picture where two child sharing one ice cream and showed static variable analogy. For more info please read Head First Java.
Upvotes: 1
Reputation: 142
I suppose the best way to think of it is that "static" means unchanging, and it is the location of the variable that is unchanging when when you switch between the different instances of a class. The main thing is to eradicate any thought from your mind that the value of a static variable is unchanging: it may even be changed by another instance of the same class.
Upvotes: 7
Reputation: 713
It's a hold over from C++ and C before that. In the C context, one of its meanings was for variables that keep their value between invocations. I presume that's where 'static' comes from - it doesn't reset the value (as opposed to a const where the value cannot change)
Upvotes: 11
Reputation: 7347
Definition of STATIC 1 : exerting force by reason of weight alone without motion 2 : of or relating to bodies at rest or forces in equilibrium 3 : showing little change 4 a : characterized by a lack of movement, animation, or progression b : producing an effect of repose or quiescence 5 a : standing or fixed in one place : stationary b of water : stored in a tank but not under pressure
just apply the definition to a variable...
Upvotes: -3