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

ABAp - OOPS :Static Type Should Be More General Than Dynamic Type Of A Reference Variable In Method Programming.

REPORT YSUBOOPS18.

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

class c1 implementation.
method m1 .
write:/5 ' I am m1 of c1'.
endmethod.
endclass.

class c2 definition inheriting from c1.
public section.
methods : m1 redefinition.
methods : m2 .
endclass.

class c2 implementation.
method m1.
write:/5 'I am m1 of c2'.
endmethod.
method m2.
write:/5 'I am m2'.
endmethod.
endclass.

START-OF-SELECTION.
DATA : OREF11 TYPE REF TO C1.
CREATE OBJECT : OREF11 TYPE C2.

CALL METHOD : OREF11->M2 .


Output:

Compilation error fails to identify method M2 in the last statement of the program.

No comments:

Post a Comment