Inheritance of three object-oriented features
Inheritance is a concept in object-oriented software technology. If a Class A inherits from another class B, this class A is called the Child class of B, and B is called the parent class of. Inheritance allows the subclass to have various attributes and methods of the parent class without having to write the same code again. When the subclass inherits the parent class, you can redefine some attributes and rewrite some methods to overwrite the original attributes and methods of the parent class, make it have different functions than the parent class. In addition, it is also common to append new attributes and methods to child classes.
Some programming languages support multi-inheritance, that is, a subclass can have multiple parent classes at the same time, such as the C ++ programming language. In some programming languages, A subclass can only inherit from one parent class, such as the Java programming language. In this case, you can use interfaces to achieve similar effects as multi-inheritance.
Inheritance concepts can be implemented in three ways: Implementation inheritance, interface inheritance, and visual inheritance.
Implementation Inheritance refers to the ability to use the attributes and methods of the base class without additional encoding;
Interface inheritance only uses the names of attributes and methods, but the subclass must provide implementation capabilities;
Visual Inheritance refers to the ability of sub-forms (classes) to use the appearance of base Forms (classes) and implement code.
Why inherit?
1. code reuse (subclass can inherit the public members of the parent class)
2. polymorphism (mentioned later)
Inheritance features:
1. Single inheritance (that is, each subclass can have only one parent class, while one parent class can have multiple child classes)
2. Inheritance (Child classes can inherit the common members of the parent class)
3. The subclass cannot inherit the constructor of the parent class (No parameter constructor of the parent class is called by default)
All classes inherit the object class by default. (If a class does not show a class, it inherits from the object class by default)