The difference between local variables and member variables:
Local variable | Member variables | |
Define location | Method internal or method | Inside the class, outside the method |
Life cycle |
Produced as the method is called, and disappear as the method is executed | Produced with the creation of objects, and disappeared with the destruction of objects |
Memory location | Follow the method to enter the stack memory | Follow the object into the heap memory |
Initial value | No initial value, an initial value must be given | Has a default value |
The initial value of the member variable:
Integer 0
decimal 0.0
character Null character
Boolean false
Reference null