What is up-casting and down casting? with example

Answer Posted / vamsi krishna srirangam

upcasting is used to acess the common methods of
subclass(which are redefined from super class) using super
class reference.
use:because of this only polymorphism is possible.
example:
lcl_truck,lcl_bus are subclasses to lcl_vehicle

vehicle_list type table of ref to lcl_vehicle.

lcl_vehicle = lcl_truck.
append lcl_vehicle to vehicle_list.
clear lcl_vehicle.

lcl_vehicle = lcl_bus.
append lcl_vehicle to vehicle_list.
clear lcl_vehicle.
now if you redefine the estimate_fuel method in each
subclass then that particular method only called because
fuel estimation is different for bus and truck.

Down-casting:
to take control back to the object that is called now.
to identify the triggered subclass object from the list of
available subclass objects.

?= means check whether the reference(path)
is same. if left hand path is equals to right hand path then
it copies the right hand path to left hand variable.
it is used to pick one from several

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between the function module and a normal abap/4 subroutine?

867


What are roles and authorization objects?

1445


Explain about Recording Function?

897


What is the difference between get and get late?

839


while implementing badi what are the tables u find??

3848


What is an abap instance?

853


Reports: Event functionality.

1109


Can we make use of flow logic control key words in abap/4 and vice-versa?

804


What are secondary indexes. How can we know which index is being used in a select query?

1214


What is the use of the raising exception?

775


What is an abap dictionary? : abap data dictionary

803


How is the command suppress-dialog useful?

861


How do you find the information on the current screen? : abap bdc

844


can any one answer these questions 1)How do you convert non-character field to character field? 2)How do you work with semi colon separated files? 3)why cant we use normal function module for data transfer? 4)what is the structure of CTU-PARAMS? 5)can we use transfer dataset to transfer data in internal table?

1780


Fallback class

1996