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

In Java, can a static variable be something other than a static class variable? It seems that the class of the classifier is not strictly necessary when referring to static variables other than being super understandable.

+3


source to share


4 answers


There is one field here that can be static and not associated with a class: interface constants , which are both static and finite (and therefore not exactly "variable", since they do not change).



You can use them even without initializing the interface implementation, so they are not necessarily associated with a class at all. I believe they are initialized when using the interface .

+2


source


From the Java Language specification, fields

A static field, sometimes called a class variable, is instantiated when the class is initialized (ยง12.4).



They are the same.

+3


source


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

0


source


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

0


source







All Articles