if the class is an essential part of these modern programming languages, including C + + and Java, then inheritance and derivation are related to the same life and death. By inheriting the classes and objects to adapt to the changing problem domain, as much as possible reuse existing classes and objects, to transform and expand them, improve the efficiency of program design. Because members have different permissions, their access rights will change as they inherit, and then they will be introduced.
* Inherit
inheritance is a development relationship between a class and a class, and the inherited class is called a base class (or a parent class), and a class of two inheriting base classes is called a derived class (or subclass). In the book "C + + Language Programming Course" published by Tsinghua University Press, it is pointed out that through inheritance, a new class is derived from the original, defined class, inherits the properties and behavior of the original class, and can extend new properties and behavior, or update the members in the existing class.
* Inheritance Category:
Because there are complex relationships between classes and classes, naturally, inheritance will have different ways, depending on the number of inheritance can be divided into single inheritance and multiple inheritance, each derived class has and only one base class is called single inheritance, if a derived class has two or more than two base class is called multiple inheritance.
diagram:
* Inheritance mode:
inheritance has public inheritance, private inheritance, and protection inheritance. the base class and the member properties of the derived class after the use of different inheritance methods in the base class and derived classes are shown in the following table
properties in the base class |
Inheritance Way |
How to access in a derived class |
Public Members |
Total Inheritance |
Public |
Protect Members |
Protect |
Private Members |
not directly accessible |
Public Members |
Protect Inheritance |
Protect |
Protect Members |
Protect |
Private Members |
not directly accessible |
Public Members |
Private Inheritance |
Private |
Protect Members |
Private |
Private Members |
not directly accessible |
* Derivation
A derived class owning an attribute of a base class is called inheritance, and the process of deriving a derived class from a base class is called a derivation. Inheritance and derivation are a pair of same life and death relationship.