Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Declarations →  Declaration Statements →  Classes and Interfaces →  ABAP Objects - Overview 

Inheritance

The concept of inheritance makes it possible to derive new classes from existing classes. This is done using the addition INHERITING FROM of the statement CLASS ... DEFINITION. The new class adopts or inherits all components of the existing class. The new class is called a subclass and the existing class is called a superclass.

If no further declarations are made, a subclass contains exactly the components of the superclass. However, only the components of the public, protected, and package visibility sections of the superclass are visible in the subclass. Although the private components of the superclass are also contained in the subclass, they are not visible. In a subclass, private components with the same name as the corresponding components of the superclass can be declared. Each class works with its private components. As long as a method inherited from the superclass is not redefined, it uses the private attributes of the superclass and not the possible subclass attributes of the same name.

If the superclass does not have a private visibility section, the subclass is an exact copy of the superclass. It is possible, however, to add further components to the subclass. These components are used to specialize the subclass with respect to the superclass. If a subclass is itself used as the superclass for a new class, it can be specialized further.

Each class can have multiple direct subclasses, but only one direct superclass. ABAP Objects applies the principle of single inheritance. If subclasses inherit from superclasses that are themselves subclasses, all classes involved represent an inheritance tree whose specialization increases each time a hierarchy level is added. Specialization decreases the closer a level is located to the root node of the inheritance tree. The root node of all inheritance trees in ABAP Objects is the predefined empty class object. This class is the most generic class because it does not contain attributes or methods. When a new class is defined, it must not be specified explicitly as a superclass because it always exists implicitly. In the inheritance tree, two neighboring nodes are known as the direct superclass and subclass, while all preceding and succeeding nodes are collectively referred to as superclasses and subclasses. The declaration of the components of a subclass is distributed among all superclasses of the inheritance tree.

Other versions: 7.31 | 7.40 | 7.54

Programming Guideline

Avoid using deep inheritance hierarchies

Executable Example

Inheritance

Continue

Redefining Methods

Abstract and Final Methods and Classes

Inheritance and Polymorphism

Inheritance and Interfaces

Inheritance and Visibility

Inheritance and the Component Namespace

Inheritance and Static Components

Inheritance and Constructors

Inheritance and Instantiation

Inheritance and Events