Java differences in member variables and local variables

Different position in the class of focus

Member variables: class, method outside

Local variables: the process or method declaration (formal parameter)

 

Scope is not the same focus

Member variables: class

Local variables: the method

 

Different initial values of focus

Member variable: there are defaults

Local variables: no default. You must define, assign, and finally use

 

Different location in memory of understanding

Member variables: heap memory

Local variables: Stack Memory

 

Lifecycle different understanding

Member variables: With the creation of the object exists, the object disappear with the disappearance

Local variables: With call a method exists, along with the method call is completed disappear

 

Guess you like

Origin www.cnblogs.com/libinhong/p/10988834.html
Recommended