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

ABAP - OOPS : Subclasses Of Friend Class Can Also Become Friends.

REPORT YSUBDEL.

CLASS C1 DEFINITION DEFERRED.

CLASS C2 DEFINITION FRIENDS C1 .
PROTECTED SECTION.
DATA : NUM TYPE I VALUE 5.
ENDCLASS.

CLASS C2 IMPLEMENTATION.
ENDCLASS .

class c1 definition.
public section .
methods : m1.
endclass.

class c1 implementation.
method m1.
DATA : OREF2 TYPE REF TO C2.
CREATE OBJECT OREF2.
WRITE:/5 OREF2->NUM.
ENDMETHOD.
endclass.

class c11 definition inheriting from c1.
public section.
methods : m11.
endclass.

class c11 implementation.
method m11.
DATA : OREF2 TYPE REF TO C2.
CREATE OBJECT OREF2.
WRITE:/5 OREF2->NUM.
endmethod.
endclass.

START-OF-SELECTION.
DATA : OREF11 TYPE REF TO C11.
CREATE OBJECT OREF11.
CALL METHOD OREF11->M11.


Output: 5

No comments:

Post a Comment