The difference between a member variable and a local variable has a few points:
1. Differences in Location:
A member variable is a variable within a class that is defined outside the method.
A local variable is a variable that is defined within a method.
2. Difference in function:
The function of a member variable is used to describe a property of a thing.
The function of a local variable is to provide a variable to use inside the method.
3. Differences in life cycle:
The life cycle of a member variable is created as the object is created and disappears as the object disappears.
When a local variable is called to the corresponding method, it is executed when the local variable statement is created, and the local variable disappears immediately after its own scope.
4. Differences in initialization:
The member variable has a default initial value. The exact initial value depends on the data type of the variable.
int 0
Double 0.0
Float 0.0f
Char '
Boolean false
String NULL
A local variable has no default initial value. To initialize before it can be used.
The difference between a member variable and a local variable