Rules for Redefining method in Sub Class in SAP ABAP
- While redefining the method in child class then name,input parameter, return type should be suitable with the method used in parent class.
- “REDEFINITION” keyword should be used while redefining the child class.
- Need not to write the interface again for the child while redefining.
- If the access control of method in parent class is public then redefinition of child class method should be either public or protected.
Redefining Methods in Subclasses:
CLASS Parent_class DEFINITION.
PUBLIC SECTION.
METHODS: display.
DATA: parent_data TYPE string.
ENDCLASS.
CLASS Child_class DEFINITION INHERITING FROM Parent_class.
PUBLIC SECTION.
METHOD:display REDEFINITION.
DATA: child_data TYPE string.
ENDCLASS.
Lets see how the rules of redefinition have been used in the above code.
- Rule 1:- We have used the same method name (display) and return type (string) in the child class and parent class.
- Rule 2:- “REDEFINITION” keyword is used to redefine the method in child class.
- Rule 3:- Access control of parent class and child class is also same as shown in the code i.e. “PUBLIC”.
SAP ABAP | Understanding Inheritance
As we know there are four pillars of object-oriented programming language. In the same way, SAP ABAP (Advanced Business Application Programming) also has four pillars: Encapsulation, Inheritance, Abstraction, and Polymorphism. In this article, we are going to learn about Inheritance in ABAP, child class, Parent class, and access control. We will also learn about the implementation of inheritance with the help of examples and redefining the methods in subclasses.