Chapter 4 Knowledge Points

Inheritance: To satisfy the relationship of is a, inheritance can be achieved through the keyword extends.


1. It will inherit the properties and methods of the parent class (excluding properties and methods modified with private)


2. The inherited keyword is extends


3. Inherited The object is called the parent class, and the inheritor is called the child class


. 4. The constructor of the parent class can only be called by the child class and cannot be inherited.


5. Any class has a default parent class Object (object)


to override and Overloading


Overriding : A method with the same name that occurs between a parent class and a child class requires that the method name, parameter list, and return value type be the same. The access modifier cannot be smaller than the parent class.


Overloading: occurs in the same class , requires the same method name to have a different parameter list, regardless of the return value type and access modifier


super: call the properties and methods of the parent class, if the constructor of the parent class is called, the location must be the first in the constructor body of the child class Line of code


Call execution order: member variables of the parent class > constructors of the parent class > member variables of the subclass > constructors of the subclass


Access modifier


1, public : As long as the methods and properties of this project can be accessed
2, private: modified properties and methods can only be used in this class
3, protected: modified properties and methods can be used in the same package subclass  
4, default: this class is the same package

Guess you like

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