|Home • Trainings • Quiz • Tips • Tutorials • Functional • Cert Q's • Interview Q's • Jobs • Testimonials • Advertise • Contact Us|
Tutorial on Wide casting
By Vineesh Batchu
This tutorial is of OOP’s ABAP on concept of Wide casting.
assignment of a superclass instance to a reference variable of the type
"points to sub class" is described as a Wide casting, because here we
are switching from a more generalized view to a one with more detail
Note:- In order to
implement wide casting first we need to implement the narrow casting.
Here I am
taking the example of calculation of area of rectangle and area of cube.
implementation of Super Class:-
In the above picture the class class_super is the super class and has one method area
which is to find the area of rectangle. The method has two parameters
w_length, w_breadth for length and breadth.
implementation of sub class:-
In the above picture the class class_sub is the sub class which is inheriting from the super class class_super.
This sub class has one method area
which is same as that of super class and redefined for calculating the area of
cube. This method has one more parameter W_height along with w_length and
w_breadth. This method finds the
area of cube.
In above screen two reference variables have been declared for
super class and one reference variable is declared for sub class.
Now create the objects for the super and base class.
Call the method Area of
super class as below:
of Narrow casting:- As
I discussed in introduction in order to implement wide casting we need to first
implement narrow casting.
are assigning the value ‘10’ to ‘w_height’ instance variable of subclass
above picture we are assigning the sub class instance reference variable to
super class instance reference variable. This is known as narrow casting.
the instance of the super class(object_superclass) now points or refers to the
object of the subclass, thus the modified method 'area'
of the subclass is accessible. Now we can call the method Area
of subclass class_sub to calculate the area of cube.
Please send us your feedback/suggestions at webmaster@SAPTechnical.COM
©2006-2007 SAPTechnical.COM. All rights reserved.
product names are trademarks of their respective companies. SAPTechnical.COM
is in no way affiliated with SAP AG.
Graphic Design by Round the Bend Wizards