1: Differences between member variables and local variables (understanding)
(1) Different positions in the class
Member variables: Outside Methods in class
Local variables: In a method definition or on a method declaration
(2) different locations in memory
Member variables: in the heap
Local variables: in the stack
(3) Different life cycle
Member variables: As objects are created, they disappear as the object disappears
Local variables: As the method is called, it disappears as the method's call is complete
(4) different initialization values
Member variables: with default values
Local variables: No default values, must be defined, assigned, and then used
The difference between a static variable and a member variable
A: Belong to different
Static variable: Belongs to class, class variable
Member variables: belong to object, object variable, instance variable
B: Different memory locations
Static variables: Static area of the method area
Member Variable: heap memory
C: Different life cycle
Static variables: Static variables are loaded as the class is loaded and disappear as the class disappears
Member variables: Member variables are present as the object is created and disappear as the object disappears
D: Call Different
Static variables: Can be called by object name, or by class name
Member variable: can only be called by object name
Comparison of member variables, local variables and static variables