009 difference between the member variables and local variables

A different defined location

Local variables defined in the interior of the method, the outside member variables defined method.

Second, the scope is not the same

Local variable scope only internal methods, member variables can be common in the whole class.

Third, the default value is not the same

There is no default local variables must be assigned, and member variables have default values, rules, and the same array.

Note: The parameters of the method are local variables.

Fourth, the memory location is not the same

Local variables are on the stack memory, heap memory is stored in the member variable.

Fifth, the life cycle is not the same

With the push method local variables occurs, as the method of the stack disappear.

As a member variable object is created and produced, with the object is garbage disappear.

Published 70 original articles · won praise 4 · Views 3976

Guess you like

Origin blog.csdn.net/l0510402015/article/details/104085924