|Home • Trainings • Quiz • Tips • Tutorials • Functional • Cert Q's • Interview Q's • Jobs • Testimonials • Advertise • Contact Us|
Demo on "Narrow Casting"
By Malya Ajimera, Capgemini consulting
The assignment of a
subclass instance to a reference variable of the type "reference to super
class" is described as a narrowing cast, because you are switching from a
more detailed view to a one with less detail. It is also called as up-casting.
of narrowing casting:
A user who
is not interested in the finer points of cars, trucks, and busses (but only, for
example, in the fuel consumption and tank gauge) does not need to know about
them. This user only wants and needs to work with (references to) the
lcl_vehicle(super class) class. However, in order to allow the user to work with
cars, busses, or trucks, you generally need a narrowing cast.
of narrowing casting:
class: vehicle (contains
truck (contains more specific methods)
method4 is the specific for the sub class and remaining methods are inherited
from the super class.
create the object with reference to the subclass.
DATA: REF_TRUCK TYPE REF TO
CREATE OBJECT REF_TRUCK.
DATA: REF_VEHICLE TYPE REF TO VEHICLE.
REF_VEHICLE = REF_TRUCK.
methods using super class reference.
1. By the
super class reference (REF_VEHICLE) it is possible to access all the methods
which are defined at the super class but the implementations are taken from the
2. If any
method is redefined at the sub class then that method’s implementation which
exist at the sub class is taken in to consideration.
assume that ‘method2’ is redefined at the sub class.
method is accessed using the super class reference
can access the implementation which exists at the sub class but not from the
3. It is
not possible to access the methods which only defined in the sub class using the
super class reference.
Method4 is not accessed using reference REF_VEHICLE.
method REF_VEHICLE-> Method4.
for narrowing casting:
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