java learning day10

The difference between member variables and local variables
1. The location in the class is different. The
member variable is
outside the method in the class. The local variable is in the method outside the class. 2. The location in the memory is different. The member
variable is in the heap memory and the local variable is in the stack memory. 、The life cycle is different Member variables exist with the existence of the object, and disappear at any time when the object disappears Local variables exist with the method call, and disappear with the completion of the method call 4. Different initial values ​​Member variables have default initial values Local variables do not have default initial values, they must be defined and initialized (assigned) before they can be used =============================== ======================================= Encapsulation refers to hiding the properties and implementation details of objects, only Provide public access to the outside world. Using the private keyword: is a permission modifier. Members that can be modified (member variables and member methods) can be accessed by private members only in this class.














Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325824849&siteId=291194637