securitypolicymanager
securitypolicymanager

Reputation: 135

Why static fields are called "static"?

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

Answers (4)

Umesh Kacha
Umesh Kacha

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

Elroch
Elroch

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

Kaffiene
Kaffiene

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

Scott M.
Scott M.

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

Related Questions