Home > Java > javaTutorial > body text

The difference between member variables and local variables

巴扎黑
Release: 2017-06-26 11:09:28
Original
3428 people have browsed it

The difference between member variables and local variables:

1. Different positions in the class

Member variables: in the class, outside the method

Local variables: in In the method definition or method declaration

2. The location in the memory is different:

Member variables: in the heap memory

Local variables: in the stack memory

3. Different life cycles:

Member variables: exist with the creation of the object, and disappear with the disappearance of the object

Local variables: exist with the call of the method , disappears as the method call is completed

4. Different initialization values

Member variables: have default initialization values

Local variables: no default initialization values, must be defined, Assign a value before it can be used.

Note:

The local variable name can be the same as the member variable name. When used in a method, the proximity principle is adopted.

The above is the detailed content of The difference between member variables and local variables. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!