- Tech know how online


Inheritance is one of the basic principles of object-oriented programming. There, starting from existing classes, new classes can be created that initially have the same properties and methods as the source class. The new class is called derived class or subclass, the source class as superclass or superclass. The derived class can override the properties and methods inherited from its superclass or add additional ones.

Inheritance is usually used in the form of subclasses having more specialized capabilities than their ancestors. The process of derivation is therefore also called specialization. The superclass thus implements general capabilities that can and should be used by all subclasses, while the subclasses specialize in other capabilities based on this. Nearly each subclass can be again superclass for a still further specialization. Exceptions exist in some programming languages, where a class can be declared as the "end of the class hierarchy" to prevent further derivation.

Inheritance with subclasses and superclasses

Inheritance with subclasses and superclasses

A distinction is made between single and multiple inheritance. With single inheritance each class has at most one superclass, with multiple inheritance there can be several. Multiple inheritance is supported by C++, for example, while more modern languages such as C-Sharp (C#) and Java do not allow it due to the low benefit compared to the problems it creates. Many practical problems for which multiple inheritance is desirable can be solved even more elegantly and generally by the design pattern" interface".

Repeated inheritance specifically means multiple inheritance of the same features due to a multiple superclass. The features of a multiple superclass can each exist multiple times in derived classes, the subclasses, depending on the semantics of the inheritance. Repeated inheritance can cause conflicts based on the multiple use of the names of features.

Englisch: inheritance
Updated at: 09.12.2009
#Words: 289
Links: object (O), class, process, hierarchy, C++
Translations: DE

All rights reserved DATACOM Buchverlag GmbH © 2024