Are static variables or methods treated similarly to a global variable or method? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Are static variables or methods treated similarly to a global variable or method?

In other terms, can "global" and "static" be used relatively interchangeably?

15th Jul 2018, 12:27 AM
Nick
Nick - avatar
1 Answer
+ 4
No. Global variables and static variables are different. That said, there are no global variables in Java, let alone a "global" keyword, as far as I am concerned. The closest you can get would be a class member defined as "public static". "static" declares that the class member belongs to the class instead of the instance of the class, and "public" declares that the class member can be accessed by other classes.
15th Jul 2018, 12:45 AM
Hatsy Rei
Hatsy Rei - avatar