Program
REPORT Z_INHERITANCE_EX. *name of the project
CLASS Parent_class DEFINITION. *Class name Parent_class
PUBLIC SECTION. *Access control is public
METHODS: display REDEFINITION.
DATA: data TYPE string. *Data attribute of string type
ENDCLASS.
*implementation of display method below
CLASS Parent_class IMPLEMENTATION.
METHOD display.
WRITE :/ ’parent_data=’, data.
ENDMETHOD.
ENDCLASS.
* child_class inherited from parent_class
CLASS Child_class DEFINITION INHERITING FROM Parent_class.
* starting of the public section of the class
PUBLIC SECTION.
METHOD :display REDEFINITION.
* declared subclass of string type
DATA: subclass_data TYPE string.
ENDCLASS.
*implemantion of child class
CLASS Child_class IMPLEMENTATION
METHOD display.
WRITE:/ ’Child_data=’, subclass_data. “to display message in “subclass_data”
ENDMETHOD.
ENDCLASS.
* DEFINING OBJECT REFERENCES.
DATA Parent_instance TYPE REF TO Parent_class.
DATA Child_instance TYPE REF TO Child_class.
*instance for parent
CREATE OBJECT Parent_instance.
*instance for child
CREATE OBJECT Child_instance.
*attributes setup of base and derived class
Parent_instance->data=’This is Parent_data’.
Child_instance->data=’This is Child_data’.
Child_instance->data =’Subclass_data=’This is specific_child data’.
*displaying data
CALL METHOD Parent_instance->display.
CALL METHOD Child_instance->display.
Output:
Parent_data=This is Parent_data
Child_data=This is specific_child data
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.