There are two types of member variables for the ①java class:
A variable that is modified by the static keyword, called a class variable or static variable Another no static modifier, for member variables ② popular Point said: The static variables of the class are only one in memory, and the Java Virtual machine allocates memory for static variables in the process of loading the class, and the static variable is in the method area and is shared by all instances of the class. Static variables can be accessed directly from the class name, depending on the life cycle of the class. The instance variable depends on the instance of the class. Each time an instance is created, the Java Virtual machine allocates memory for the instance variable once, and the instance variable is in the heap, whose life cycle depends on the life cycle of the instance. NOTE: The order of initialization in 1.java: load class; static variable initialization; static block; " It can only dispatch static, cannot dispatch non-static " member variable; construction method; 2. To show the priority of a static block, I'm going to show a program without the main method, javac it without any errors. public class Test { static { System.out.println ("Static"); &Nbsp; system.exit (0); }}
The difference between static and non-static variables in Java