The difference between static variables and member variables:
A: Different
Static variables: belong to a class, class variables
Member variables: belong to objects, object variables, instance variables
B: Different memory locations
Static variable: static area of method area
Member variable: heap memory
C: Different life cycles
Static variables: Static variables are loaded as the class is loaded and disappear as the class disappears.
Member variables: Member variables exist as the object is created and disappear as the object disappears.
D: The call is different
Static variables: can be called by object name or by class name
Member variable: can only be called by object name
The difference between member variables and local variables:
A: Different positions in the class
Member variable: outside of the method in the class
Local variables: in the method definition or method declaration
B: Different locations in memory
Member variable: in heap memory
Local variables: in the stack
C: Different life cycles
Member variable: exists as the object is created, disappears as the object disappears.
Local variables: exist as the method is called and disappears as the method is called.
D: The initialization value is different
Member variable: There is a default initialization value
Local variables: There is no default initialization value, it must be defined and assigned before it can be used.
Notes:
Local variable names can be the same as member variable names. When used in methods, the principle of proximity is adopted.
The above is all the content that the editor has brought to you about the differences between static variables, member variables and local variables. I hope it will be helpful to everyone and support Wulin.com more~