What are static variables?
Static variables refer to variables modified by the static keyword, also called class variables.
There is only one static variable of the class in memory. The Java virtual machine allocates memory for static variables during the process of loading a class. The static variables are located in the method area and are shared by all instances of the class. Static variables can be accessed directly through the class name, and their life cycle depends on the life cycle of the class.
(Video tutorial recommendation: java video)
Let’s take a look at the order of initialization in JAVA:
Loading class;
Static variable initialization;
Static block; [It can only schedule static ones, not non-static ones]
Member variables;
Construction method;
Recommended tutorial: java entry program
The above is the detailed content of What is a static variable in java. For more information, please follow other related articles on the PHP Chinese website!