Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any other type of static variable in Java than a static class variable?

Tags:

java

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.

like image 378
Julian A. Avatar asked Jan 28 '26 06:01

Julian A.


2 Answers

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.

like image 126
Sotirios Delimanolis Avatar answered Jan 29 '26 20:01

Sotirios Delimanolis


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.

like image 41
Lunivore Avatar answered Jan 29 '26 20:01

Lunivore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!