The difference between the local variables and member variables

variable

Depending on the location of the definition, we give the variables played a different name. As shown below:
Different positions in the class 
  • Member variables: class, method outside
  • Local variables: the process or method declaration (formal parameter)
Scope is not the same 
  • Member variables: class
  • Local variables: the method
Different initialization values 
  • Member variable: there are defaults
  • Local variables: no default. You must define, assign, and finally use
Different locations in memory 
  • Member variables: heap memory
  • Local variables: Stack Memory
Different life cycle 
  • 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/wurengen/p/10959001.html