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

ABAP - OOPS: Methods Using Private Attributes In Method Programming.

As long as a method( using private attributes) inherited from a superclass is not redefined, it still uses the private attributes of the superclass, not those of the subclass, even if the subclass has private attributes of the same name.
-------------------------------------------------------------------------------------------

report ysubdel .

CLASS c1 DEFINITION.
PUBLIC SECTION .
METHODS : m1 .
PRIVATE SECTION.
DATA : num TYPE I VALUE 5 .
ENDCLASS.

CLASS c1 IMPLEMENTATION.
METHOD : m1 .
write:/5 num .
ENDMETHOD.
ENDCLASS.

CLASS c2 DEFINITION INHERITING FROM c1.
PUBLIC SECTION .
DATA : num TYPE I VALUE 6.
ENDCLASS.

CLASS c2 IMPLEMENTATION.
ENDCLASS.


START-OF-SELECTION.
DATA : oref2 TYPE REF TO c2 .

CREATE OBJECT : oref2 .

CALL METHOD oref2->m1 .


Output: 5

No comments:

Post a Comment