Google Search - Blog...........

ABAP - Subclass Re-Implementing Inherited Methods From Superclass In Method Programming.

REPORT YSUBDEL.
CLASS C1 DEFINITION.
PUBLIC SECTION.
METHODS : METH1.
PROTECTED SECTION.
METHODS METH2.
ENDCLASS.

CLASS C1 IMPLEMENTATION .
METHOD : METH1.
WRITE:/5 'I am meth1 in class C1'.
CALL METHOD METH2.
ENDMETHOD.

METHOD : METH2.
WRITE:/5 ' I am meth2 in class C1 '.
ENDMETHOD.
ENDCLASS.

CLASS C2 DEFINITION INHERITING FROM C1.
PUBLIC SECTION.
METHODS : METH1 redefinition .
PROTECTED SECTION.
METHODS : METH2 redefinition.
ENDCLASS.

CLASS C2 IMPLEMENTATION.
METHOD METH1.
WRITE:/5 'I am meth1 in class C2'.
call method meth2.
endmethod.

METHOD : METH2.
WRITE:/5 ' I am meth2 in class C2 '.
ENDMETHOD.

endclass.

START-OF-SELECTION.
DATA : OREF1 TYPE REF TO C1 ,
OREF2 TYPE REF TO C2.
CREATE OBJECT : OREF1 , OREF2.
CALL METHOD : OREF1->METH1 ,
OREF2->METH1.

Output
I am meth1 in class C1
I am meth2 in class C1
I am meth1 in class C2
I am meth2 in class C2

No comments:

Post a Comment