[Distinguish member variables and local variables]

A: Different positions in the class:
Member variables: an outer class method.
Local variables: the definition of the process or method declarations.
B: different locations in memory:
Member variables: the heap memory
Local variables: the stack memory
C: Life Cycle different:
Member variables: With the creation of the object exists, with the disappearance of the object disappear.
Local variables: With call a method exists, along with the method call is completed and disappear.
D: Different initial values:
Member variable: there is a default initial value.
Local variables: no default initial value must be defined, assigned before you can use.
 
Precautions:
Local variables and member variables can name the same name, when used in the method, using the principle of proximity.
 
Issue formal parameters:
Basic types: the formal parameter change does not affect the actual parameters.
Reference types: change the form parameters affect the actual parameters.

Guess you like

Origin www.cnblogs.com/zuixinxian/p/11276364.html