Review of various knowledge points

1. Initialization

1. Summary of this.super, constructor, construction code block, and static code block.

this: represents the current object, that is, the reference to the object to which the function belongs.
This object is followed by. The member variables and methods of the object are called. (this.say());
Add () after this object to call the constructor of the corresponding parameter in this class.

super: represents the parent class, which is the parent class of the current class.
The usage is similar to this.

Constructor: A special function called when an object is initialized, executed only once.
To use this or super in a constructor, it must be defined in the first line of the constructor. If it is not used, then the first sentence of the constructor will add super() by default;
construction code block: it is to initialize all objects, that is, a code block that all objects will call, as long as the object is created , this code block is called for common initialization of different objects, which takes precedence over constructor execution.
Format: {
code. . . . . .
}
Static code block: A code block area marked with the static keyword, defined in the class. The initialization of the class can be completed, and the static code block will be executed once as the class is loaded (multiple new objects are also executed only once). If it is in the same class as the main function, it takes precedence over the main function.
Format: static{
code. . . . .
}
The execution order of three initializations: static code block ---> construction code block ------> constructor.

2. Inheritance (extends):

1. Overriding and overloading

Override: Override the existing method of the parent class, and the method of the child and parent class must be exactly the same. (Including the return value, when the subclass overrides the parent class method, the access rights must be greater than the parent class or the same level. The methods are either static or not static).
Overloading: multiple methods only in this class, only look at the parameter list of the function with the same name.
When the subclass is initialized, the methods and variables of the parent class are initialized first, and then their own are initialized.
3. Interface (implements)

1. Realize

Interfaces can be multi-implemented, and class inheritance can only be single-inherited.
There is an inheritance relationship between interfaces, and interfaces can inherit multiple interfaces.

4. Polymorphism

Embodiment: The reference of the parent class or interface points to its own subclass object. (Note: When using polymorphism, to access the method of the subclass, it is required that the method must be declared or defined in the parent class).

The characteristics of polymorphism in the members of the sub-parent class:

Member variable:
compile time: whether there is a called member in the class to which the reference type variable of the reference belongs. (No objects are produced at compile time, only syntax errors are checked).
Runtime: It is also a member that refers to whether there is a call in the class to which the reference type variable belongs.
A brief summary: member variables - compile and run all look at the left side of =.

Non-static member function:
compile time: refer to whether there is a method called in the class to which the reference type variable belongs.
Runtime: Refers to whether there is a method called in the class to which the object belongs.
Reason: Because there is a feature in the amorphous member function of the child parent class: override (override).
Brief summary: member functions - compile to see = left, run to see = right.
Static function:
compile time: refer to whether there is a method called in the class to which the reference type variable belongs.
Runtime: The reference is whether there is a method called in the class to which the reference type belongs.
Reason: Because it is a static method, it does not belong to the object, but belongs to the class where the method is located.
Brief summary: member function - compile and run to see = left side,

Guess you like

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