ooabap
ooabap
1. Normal Class
A normal class in ABAP is simply a class that contains methods and attributes
without any special characteristics like inheritance or interfaces.
Example:
abap
CLASS lcl_normal DEFINITION.
PUBLIC SECTION.
DATA: gv_text TYPE string.
METHODS: set_text IMPORTING iv_text TYPE string,
get_text RETURNING VALUE(rv_text) TYPE string.
ENDCLASS.
METHOD get_text.
rv_text = gv_text.
ENDMETHOD.
ENDCLASS.
2. Inheritance from Class
Inheritance allows a class (subclass) to inherit attributes and methods from
another class (superclass).
Example:
abap
CLASS lcl_super DEFINITION.
PUBLIC SECTION.
METHODS: display.
ENDCLASS.
Example:
abap
CLASS lcl_abstract DEFINITION ABSTRACT.
PUBLIC SECTION.
METHODS: abstract_method ABSTRACT.
ENDCLASS.
Example:
abap
INTERFACE lif_example.
METHODS: method1,
method2 IMPORTING iv_param TYPE string.
ENDINTERFACE.
METHOD lif_example~method2.
WRITE: / iv_param.
ENDMETHOD.
ENDCLASS.
5. Multiple Inheritance Using Interfaces
ABAP does not support multiple inheritance directly, but you can achieve similar
behavior using interfaces.
Example:
abap
INTERFACE lif_interface1.
METHODS: method1.
ENDINTERFACE.
INTERFACE lif_interface2.
METHODS: method2.
ENDINTERFACE.
METHOD lif_interface2~method2.
WRITE: / 'Method2 from Interface2'.
ENDMETHOD.
ENDCLASS.