There are two types of class member variables: one is a variable modified by the static keyword, called a class variable or a static variable, and the other is a variable not modified by the static keyword, it is called an instance variable.
The difference between static variables and instance variables is:
1. There is only one static variable of the class in the memory. the Java Virtual Machine allocates memory for the static variable during the class loading process. The static variable is located in the metadata method and is shared by all instances of the class.
Static variables can be accessed directly by class names. The lifecycle of a static variable depends on the lifecycle of the class. When a class is loaded, the static variable is created and allocated memory,
When the class is detached, the static variable is destroyed and the occupied memory is revoked.
2. Each instance of the class has corresponding instance variables. Each time a class instance is created, the Java Virtual Machine allocates memory for the instance variable once, And the instance variable is located in the heap area.
The life cycle of instance variables depends on the life cycle of the instance. When an instance is created, the instance variables are created and allocated with memory. When the instance is destroyed, the instance variables
Memory occupied by destruction and revocation.