2016 Mar 17 11:20 PM
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.
2016 Mar 18 4:18 AM
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.
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
2016 Mar 18 12:01 AM
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
2016 Mar 18 4:18 AM
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.
2016 Mar 18 5:45 AM
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.
2016 Mar 18 5:52 AM
The super class is abstract, so why would you want to execute the (empty) method?
cheers
Paul
2016 Mar 18 9:01 AM
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
| User | Count |
|---|---|
| 6 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |