Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Declarative statemnts →  Classes and Interfaces →  ABAP Objects - Overview 

Inheritance

The concept of inheritance allows you to derive new classes from existing classes. To do this, you use the INHERITING FROM addition of the CLASS ... DEFINITION. The new class adopts or inherits all components of the existing class. The new class is called subclass, and the existing class is called superclass.

If you make no further declarations, a subclass contains exactly the components of the superclass. However, only the components of the public, protected, and package visibility section 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, you can declare private components with the same name as the corresponding components of the superclass. 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. You can, however, add further components to the subclass. These components are used to specialize the subclass in relation to the superclass. If a subclass is then used as the superclass for a new class, you can then define a further level of specialization.

Each class can have several direct subclasses, but only one direct superclass. ABAP Objects applies the principle of single inheritance. If subclasses inherit from superclasses that are subclasses themselves, all classes involved represent an inheritance tree whose specialization increases the more deeper hierarchy levels are 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 you define a new class, you must not explicitly specify this class 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

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