Entering content frameInheritance: Overview Graphic Locate the document in its SAP Library structure

Inheritance: Overview

This graphic is explained in the accompanying text

The left-hand part of the graphic shows how you can derive a subclass c2 from a superclass c1 using the INHERTING FROM addition in the CLASS statement. The right-hand part of the graphic shows the distribution of the subclass in the inheritance tree, which stretches back to the default empty class OBJECT. A subclass contains all of the components declared above it in the inheritance tree, and can address all of them that are declared public or protected.

Single Inheritance

This graphic is explained in the accompanying text

This graphic illustrates single inheritance. A class may only have one direct superclass, but it can have more than one direct subclass. The empty class OBJECT is the root node of every inheritance tree in ABAP Objects.

Inheritance and Reference Variables

This graphic is explained in the accompanying text

This graphic shows how reference variables defined with reference to a superclass can point to objects of subclasses. The object on the right is an instance of the class class3. The class reference variables CREF1, CREF2, and CREF3 are typed with reference to class1, class2, and class3. All three can point to the object. However, CREF1 can only address the public components of class1. CREF2 can address the public components of class1 and class2. CREF3 can address the public components of all of the classes.

If you redefine a method of a superclass in a subclass, you can use a reference variable defined with reference to the superclass to address objects with different method implementations. When you address the superclass, the method has the original implementation, but when you address the subclass, the method has the new implementation. Using a single reference variable to call identically-named methods that behave differently is called polymorphism.

Leaving content frame