Application Development and Automation 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: 
Read only

accessing super class method inside a sub class method

tharun_kumar1
Explorer
0 Kudos
874

Hello experts

I have a class CL_X created as an abstract class. In this, there is a method, called check_doc_x.

Now, I have a sub class inheriting from CL_X. In this sub class, I've redefined check_doc_x for some standalone checks. In addition I have a sub class method check_doc_y.  Now, I want to access super class method check_doc_x inside the sub class method check_doc_y. All the methods are instance methods.

Is this possible? I tried casting and it didn't work.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Kudos
827

Hi Tharun,

It is only possible to access super class method in subclass redefinition method.

METHOD check_doc_x.

     super->check_doc_x( ).

     WRITE : /'This is check_doc_x redifined'.

   ENDMETHOD. 

As mentioned about casting, you can perform only widening cast(super ref ?= sub object) but the vice versa up casting ( sub ref ?= supobj) is not possible as super class is an abstract class.

Even in case of widening cast,if you call super class method(check_doc_x),eventually it means you are calling subclass redefinition method.

  lob_x ?= lob_y.

   lob_x->check_doc_x( ).

As per my understanding,accessing super class abstract method in subclass method is not possible.I would be glad to know if its possible.

Regards

Pallavi.

5 REPLIES 5
Read only

paul_bakker2
Active Contributor
0 Kudos
827

Hi,

I'm not sure I understand your question. Do you have two levels of subclasses or one?

What happens when you try to execute super->check_doc_x?

cheers

Paul

Read only

Former Member
0 Kudos
828

Hi Tharun,

It is only possible to access super class method in subclass redefinition method.

METHOD check_doc_x.

     super->check_doc_x( ).

     WRITE : /'This is check_doc_x redifined'.

   ENDMETHOD. 

As mentioned about casting, you can perform only widening cast(super ref ?= sub object) but the vice versa up casting ( sub ref ?= supobj) is not possible as super class is an abstract class.

Even in case of widening cast,if you call super class method(check_doc_x),eventually it means you are calling subclass redefinition method.

  lob_x ?= lob_y.

   lob_x->check_doc_x( ).

As per my understanding,accessing super class abstract method in subclass method is not possible.I would be glad to know if its possible.

Regards

Pallavi.

Read only

0 Kudos
827

Thanks Pallavi,

I had this scenario and unnecessarily I am copy pasting the entire contents of super class method inside the sub class method. So maybe there is no workaround I believe.

Read only

0 Kudos
827

The super class is abstract, so why would you want to execute the (empty) method?

cheers

Paul

Read only

0 Kudos
827

The super class is abstract, but I've implemented all the methods. These are used in many of my subclasses.

When I create a sub class object and call a method, the super class method implantation is called. If I refund it in sub class, then the latter one is called.

Regards

Tharun