‎2006 Feb 28 6:27 AM
Hello All,
I have small requriemn..
I have a super class A and a sub class B.
In both the classes I have a method XYZ.
So, A has the following methods
ABC
XYZ
B has the following methods
XYZ
Now I have want to access the sub class methods from super class...i.e., in my example...Method XYZ of B class needs to be accessed from method ABC or XYZ or A.
How do I do?
And more over..what is the difference between Narrow Casting and Wide casting?
Kalyan
‎2006 Feb 28 6:49 AM
Hi Priya,
Consider the below Example for accessing the subclass method from Superclass:
CLASS LCL_SUPERCLASS DEFINITION.
PUBLIC SECTION.
METHODS: ABC, XYZ.
ENDCLASS.
CLASS LCL_SUPERCLASS IMPLEMENTATION.
METHOD ABC.
CALL METHOD ME->XYZ.
ENDMETHOD.
METHOD XYZ.
ENDMETHOD.
ENDCLASS.
CLASS LCL_SUBCLASS DEFINITION
INHERITING FROM LCL_SUPERCLASS.
PUBLIC SECTION.
METHODS XYZ REDEFINITION.
ENDCLASS.
CLASS LCL_SUBCLASS IMPLEMENTATION.
METHOD XYZ.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA: O_SUPER TYPE REF TO LCL_SUPERCLASS,
O_SUB TYPE REF TO LCL_SUBCLASS.
CREATE OBJECT: O_SUPER, O_SUB.
CALL METHOD O_SUPER->ABC.
CALL METHOD O_SUB->ABC.
In the above example, When you call the superclass method ABC using CALL METHOD O_SUPER->ABC, as you see in the implementation part of the Method it will inturn call the Superclass method XYZ.
Here ME will point to the instance of the Superclass.
But the CALL METHOD O_SUB->ABC will call the method ABC ( this is inherited from Superclass to Subclass )and inturn it calls the method XYZ of the SUbclass since ME now points to the object O_SUB of the Subclass.
Hope this is clear.
Regards,
Nirupamaa.
‎2006 Feb 28 6:55 AM
‎2008 Nov 02 8:05 PM
narrow cast is whn u wnt 2 access d redifined methods of parent class in child class or in other wrds whn u assign the instance of sub class 2 d reference of super class..
widening cast is whn u wnt 2 access d new methods of child class or in other wrds whn u assign the reference of super class to child class.