04-29-2013 3:12 PM
hi, I wrote a simple program to try to learn inheritance in oo programming. Here is part of my code:
In superclass:
METHODS: display_value IMPORTING im_value type string.
In subclass:
METHODS display_value REDEFINITION .
As you can see, superclass's 'display_value' does have a parameter while subclass doesn't.
The problem is, even if I define a data type ref to subclass like
DATA obj_dis TYPE REF TO lcl_vbap_sub.
CREATE OBJECT obj_dis.
when I wrote CALL METHOD obj_dis->display_value.
It occured an error said that I have to assign value into parameter im_value.
can anybody give me some ideas, thanks for that.
04-29-2013 4:29 PM
The method "display_value" inherits the signature (the parameters) from the superclass. Unless the parameter is optional, you have to supply it whether you're calling the method from the superclass or the subclass.
This is how ABAP Objects works.
04-29-2013 4:29 PM
The method "display_value" inherits the signature (the parameters) from the superclass. Unless the parameter is optional, you have to supply it whether you're calling the method from the superclass or the subclass.
This is how ABAP Objects works.
04-29-2013 4:43 PM
what if I need more parameters in the method in subclass than in the superclass?
I will be very appreciate if you give me some guides of how to use
"CALL METHOD super->display_value" in the redefinition of display_value in subclass.
04-29-2013 5:01 PM
Hi,
When you say REDEFINITION in a sub-class, it means that the method implementation (coding) can be changed according to the specific requirement of sub class. Like Matthew said, the method inherits signature which can not be changed.
Athreya
04-29-2013 5:11 PM
thanks.
But why some sample coding use"CALL METHOD super->display_value" in the redefinition of the method in subclass.
It is also hard to understand, compare to other languages.