|
The concept of inheritance is used to incorporate the properties of an existing class to a new class. The advantage of this feature is that the methods and the attributes of the existing class are automatically taken into the new class and of course with the option to add and enhance new features. Conceptually - Inheritance can be single inheritance (inherit from exactly one class) or multiple inheritance (inherit from more than one classes). However, unlike C++, ABAP Objecs support only single inheritance. The below diagram illustrates inheritance. 
Inheritance is one of the most powerful feature of object oriented programming. Inheritance is the process of creating new classes, called derived classes or subclasses or child classes from existing classes called base classes or super classes or parent classes. The derived class inherits all the capabilities of the base class but can add embellishments and refinements of its own. The base class is unchanged by this process.
Using Interfaces with Inheritance we can implement multiple inheritance concept in ABAP like in JAVA.
Inheritance can be single level as well as multi level. Inheritance permits code reusability. Once a base class is written and tested, it need not be touched again. Reusing existing code saves time, money and increase a programs reliability. Syntax for creating child classes: The syntax is simple (if you are using local classes) : CLASS child_class DEFINITION INHERITING FROM parent_class. However, if you are using global classes, then in class builder (transaction SE24) go the properties tab and define the super class. Visibility of attributes: The public and protected components of the super class are visible in the subclass. Private section of the super class is not visible in the sub classes. Private components of the sub class can have same name as the private component of the super class. Public and Protected components of the sub class can not have the same name as that have been used in super class.
|