3

In Java, can a static variable be anything other than a static class variable? It seems the qualifier class is not strictly necessary when referring to static variables, other than to be super clear.

Julian A.
  • 9,850
  • 12
  • 57
  • 98

4 Answers4

3

From the Java Language Specification, on fields

A static field, sometimes called a class variable, is incarnated when the class is initialized (§12.4).

They're one and the same.

Sotirios Delimanolis
  • 252,278
  • 54
  • 635
  • 683
2

There's one kind of field that can be static and isn't associated with a class: interface constants, which are both static and final (and therefore not exactly a "variable", since they don't vary).

You can use them even without initializing an implementation of the interface, so they're not necessarily associated with a class at all. I believe they're initialized when the interface is used.

Community
  • 1
  • 1
Lunivore
  • 16,218
  • 4
  • 41
  • 86
0

Static variables are class variables, in that they all live within the context of a class, but you need to be careful in that you can have a static int, or a static string, etc, as well as a static class variable.

Gwyn Evans
  • 1,231
  • 6
  • 17
0

Static fields are always associated with a class, but you don't need to write the class name if you are referencing the field from the same class.

BladeCoder
  • 11,697
  • 2
  • 51
  • 46