class variable : shape as static int A; As the name implies, a class variable can be understood as a variable of a class, and a class variable is allocated a memory space when the class is loaded, unlike an instance variable (int A; ), an instance variable allocates memory when the class creates an object. And, each time an object is created, the instance variable is allocated the appropriate memory space, and the class variable does not belong to any one object, it is shared with all objects, and the class variables of all objects occupy the same memory space. The class name can be used during the invocation of a class variable . Class variables can also be called by the object name. Class Variable . The class variable is the same as the static variable that is contacted in C + + and has memory function.
class method: static void Show (); Like class variables, class methods are also part of the class, and when the class is loaded, it assigns the entry address to the class method, and the instance method is assigned the entry address only after the object is created. Similarly, the class method can be called by all pairs, and can be called with the class name . class method or object name. class Method . Instance methods can only be called with object names. It is important to note, however, that class methods cannot invoke instance variables, because class methods are allocated at the time the class is loaded, and at this point the object may not be created to allocate memory space for the instance variable, that is, the instance variable may not exist, so you cannot invoke the instance variable with a class method. An instance method can invoke all instance variables and class variables.
Both instance variables and instance methods release memory space when the object dies, and class variables and class methods release all memory space until the program runs out of date.
The differences between class variables, instance variables, class methods, and instance methods in Java