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

ABAP - OOPS: Subclass Accessing Public / Protected Components Of Superclass In Method Programming.

REPORT YSUBDEL.
CLASS C1 DEFINITION.
PUBLIC SECTION.
METHODS : METH1.
DATA : NUM TYPE I VALUE 6.
PROTECTED SECTION.
DATA : num2 type i value 7.
METHODS METH2.
ENDCLASS.

CLASS C1 IMPLEMENTATION .
METHOD : METH1.
WRITE:/5 num.
endmethod.

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

CLASS C2 DEFINITION INHERITING FROM C1.
PUBLIC SECTION.
METHODS : M1.
ENDCLASS.

CLASS C2 IMPLEMENTATION.
METHOD M1.
CALL METHOD : meth1, meth2.
write:/5 num2.
endmethod.
endclass.

START-OF-SELECTION.
DATA : OREF TYPE REF TO C2.
CREATE OBJECT OREF.
CALL METHOD : OREF->M1.


Output 6
I am meth2
7

No comments:

Post a Comment