Inheritance defines the relationship between classes, in which a class (subclass) uses the structure and behavior that has already been defined in one or more other classes (superclasses). So simply this means "Inheritance is about reuse!".
Allow me to use a concrete example to explain inheritance: Collection.
A collection is any number of objects (more precisely object references). However, there could be many types of collection. Therefore, I will implement each type of collection as a class. In principle this approach is correct. However, you will soon establish that all collections have several components in common like:
1. Each class requires a method in order to add objects to a collection.
2. Each class requires a method in order to delete objects from a collection.
3. Each class has a method which identifies the number of object references in the collection and so on.
Inheritance is the solution to this situation. You implement all of the similarities in the class which is Superclass. You then implement the individual types of collection in their own classes which are Subclassesof the Superclass. As a subclass, these classes inherit all of the components of the Superclass. Attributes, methods and events are inherited. In addition, you can implement additional attributes, methods and events in the subclass.
POLYMORPHISM
Polymorphism occurs, where classes implement the same functionality with different methods (one functionality, several methods but the same name). This can occur via an inheritance relationship, in that the methods belonging to the superclass are redefined in the subclasses and implemented differently. ABAP Objects requires the method names to be the same and the signature to be the same (signature = method interface).
Polymorphism can be achieved in 2 ways:
(1) Two independent classes implement methods with the same names and the same signature with the intention, that the methods should be called dynamically from a third location.
(2) A superclass implements a method, and in a subclass you want to re-implement the same method, as the superclass implementation is not suitable for the subclass.
The first scenario will not occur very often in ABAP Objects, as the interface concept was created precisely for such cases.
The first scenario will not occur very often in ABAP Objects, as the interface concept was created precisely for such cases.