Object Oriented Chapter 4 Knowledge Points

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

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

2. The keyword of inheritance is extends

3. The inherited 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 subclass and cannot be inherited

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

Override and overload

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

Overloading: Occurs in the same class, requiring the same method name and different parameter lists, 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 line of code in the body of the constructor of the subclass

Call execution order: member variable of parent class > constructor of parent class > member variable of child class > constructor of child class

access modifier

1, public: as long as the methods and properties of this project can be accessed
2, private: the modified properties and methods can only be used in this class
3, protected: the modified properties and methods can be used under 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=325906204&siteId=291194637