Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

inheritance problem in oo programming

raffinkira
Participant
0 Kudos

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.




1 ACCEPTED SOLUTION

matt
Active Contributor
0 Kudos

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.

4 REPLIES 4

matt
Active Contributor
0 Kudos

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.

0 Kudos

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.

Former Member
0 Kudos

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

0 Kudos

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.