Day05
- Object-Oriented Understanding: the object-oriented and process-oriented is a kind of thought in the relative process. Process-oriented emphasis is on functional behavior. Object-oriented is to encapsulate the function into objects, emphasizing the objects with functions. Object-oriented is process-oriented. Object, which is a thing with one or more specific functions. (Objects of all things)
- Object-oriented three features: encapsulation, polymorphism, inheritance.
Encapsulation (encapsulation): Refers to the properties and implementation details of hidden objects, providing public access only externally. The advantage of encapsulation is that it can isolate the changes of objects, make them easy to use, improve reusability and improve security. The principle of encapsulation is to hide content that does not need to be provided externally. Hides properties, providing public methods for accessing them. (function is the smallest wrapper in Java)
Java development, plainly, is to find objects to use, if there is no object, create an object (Find objects, build objects, use objects, maintain the relationship between objects)
- Class is the description of things in real life. object is the entity that actually exists for this kind of thing. In the computer, we can say that there are classes first, and then there are objects, because there is a class before the new object. For people, it is the first object, we will describe it, that is, the class.
- In Java, the description is class-defined classes, which correspond to the entities that Java establishes with the new keyword in heap memory, the object. (Objects are in heap memory)
- Defining a class is describing things, defining properties and behaviors. Properties and behaviors become members of the class together. The (member variable and member method) property corresponds to a variable in a class. The function (method) in the class that corresponds to the behavior.
- A member variable acts on the entire class, and the local variable acts in the function or in the statement. In memory, member variables are stored in heap memory, while local variables exist in stack memory.
- Anonymous objects: When a method on an object is called only once, it can be done with an anonymous object, which simplifies the code, but if multiple members are called on an object, the object must be given a name. (New class name. Method Name ()) Anonymous objects can also be passed as actual parameters.
- Private keyword: A proprietary, permission modifier that modifies a member (member variable, member function) in a class, a method or variable that is modified by private, and is accessible only in this class. (If you want to access a private member of a class outside of the class, you need to define a method in the class that can access this member, and then create an object outside the class to indirectly access the member in the form of a reference to this method)
Note: Private is only a representation of the package.
- The reason to provide external access in the class is that it is possible to add logical control statements in the access mode, manipulate and judge the data accessed, and provide the robustness of the code.
- Constructor: The function name, like the class name, does not need to define a return value type and cannot write a return statement. The purpose of this is to initialize the object. Whenever you create a new object, the corresponding constructor is called. When a constructor method is not defined in a class, the system defaults to a constructor that adds an empty argument to the class. Constructors in the general function in the wording of the different, in the run is also different, the constructor, when the object is established to run, the general method is the object call will be executed, is to add objects to the object has the function. An object is established, the constructor is called only once, and the general function can be called multiple times.
- When a constructor is defined, it is defined in the constructor when the object is analyzed and the object has some characteristics or behavior.
- Construct code block: format {...}, which exists in the class. The purpose of this is to initialize the object. The object runs as soon as it is established, and takes precedence over other constructor functions. The difference is that building blocks of code is used to initialize all objects uniformly, and to locate the initialization content of different object commonalities. The constructor is the initialization of the corresponding object.
This: can be used to represent a reference to the object to which the function belongs. In a nutshell, which object is calling the function where this is located, this represents which object. When defining a function in a class, the function is used internally to represent the object when the function is called. This is used as long as this type of object is used internally by this type of function. This can also be used to invoke each other between constructors.
Note: This statement can only be defined in the first row of the constructor. Because initialization is performed first. The this statement, that is, this (name) can only be used in constructors and cannot be used in general functions.
Beginners To learn Java, is javase, every day I learn from the day and notes, I hope you can criticize and advice, and promote common progress! Fifth day!