9.4 The difference between member variables and local variables

The difference between member variables and local variables :
1. Define position
member variables: in the class, outside the method,
local variables: in the method, or formal parameters

2. Initialization value
member variable: there is a default initialization value
local variable: there is no default initialization value, must first be assigned in use
Scope
member variable:
local variable in the class : in the method
3. Memory location
member variable: heap Memory
local variables: stack memory
4. Life cycle
member variables: exist with the creation of objects, and disappear with the disappearance of objects
Local variables: exist with the creation of methods, and disappear with the disappearance of methods
5. Notes
When local variables and member variables have the same name, the principle of proximity is adopted.

Guess you like

Origin blog.51cto.com/15138685/2666761