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 semi-monthly and Bi-weekly payroll area

3026


Difference between sap script and report?

750


Explain the Importance of pa20? : abap hr

635


What are the different types of the variable in the sap abap?

589


What is a modification assistant?

595






Explain different types of attributes of function module?

552


What are the tcodes for performance tuning?

915


Does SAP has a GUI screen painter or not? If yes what operating systems is it available on? What is the other type of screen painter called?

638


Can we control the sequence in which multiple implementations of a multiple use BADI are called? If yes, how?

922


In BDC, data transfer is done success in foreground mode but if we done the same in background mode it shows errors. What is the reason?

986


Explain what are standard layouts sets in the sap script?

948


What is the difference between collect and append statements?

573


i have executed a report via back ground job, in this report i have used enqueue and dequeue function modules on a table, but before releasing the lock(before dequeue function module is not call) job gives the dump, so the lock is not released the table, here my question is how to set the lock automatically release the there is a short dump before calling the dequeue module?

1734


What is the basic difference internal tables and database tables? : abap data dictionary

571


What is the name of the system variable that holds the contents of the selected line in interactive reporting?

720