7.1 Local variables and member variables

Local variables and member variables:

1. Define the position is not the same [focus]

  Local variables: the method of internal

  Member variables: the external method of directly writing them in class

 

2. The scope is not the same [focus]

  Local variables: The only way we can use them, you must manually assign

  Member variables: the whole class can be common.

 

3. The default value is not the same as [focus]

  Local variables: There is no default value, if it is to use, you must manually assign

  Member variables: If there is no assignment, there will be defaults, rules, and the same array.

 

4. The memory locations differ (learn)

  Local variables: Located in the stack memory

  Member variables: Located heap memory

 

The life cycle is not the same (to know)

  Local variables: With the push method and the birth, along with a stack method disappear

  Member variables: With the object creation and birth, as the object is garbage disappear

Guess you like

Origin www.cnblogs.com/sdrbg/p/11109714.html