Joke Collection Website - Mood Talk - The difference between inheritance and derivation

The difference between inheritance and derivation

1. Different perspectives

Inheritance is from the perspective of subclasses, and derivation is from the perspective of base classes.

2. Different definitions

Derivative means that the source of a river produces tributaries. Extended to differentiate from the development of a main thing. Inheritance is a concept in object-oriented software technology, and polymorphism and abstraction are the three basic characteristics of object-oriented. Inheritance allows subclasses to have the properties and methods of the parent class or to redefine or add properties and methods.

Extended information

In the most common form of "single inheritance", the derived class has only one base class.

In the hierarchical design of classes, some common characteristics can be found, that is, derived classes always have a "kind of" relationship with the base class.

Another noteworthy point is that Book is both a derived class (derived from PrintedDocument) and a base class (PaperbackBook is derived from Book). The following example is an outline illustration of this class hierarchy.

class PrintedDocument

{

//Member table

};

//Book is derived from PrintedDocument Derived from

class Book:public PrintedDocument

{

//Member table

};

//PaperbackBook is derived from Book

class PaperbackBook: public Book

{

//Member table

};

p>

PrintedDocument is the direct base class of Book, and it is also the indirect base class of PaperbackBook. The difference between direct base classes and indirect base classes is that direct base classes appear in the base class table of the class description, while indirect base classes do not appear in the base class table.

Baidu Encyclopedia-Derived Class