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 are the modes in lock objects? : sap abap data dictionary

819


What is an abap?

796


What are the data classes in abap?

873


What is foreign key relationship? : abap hr

852


How to set an Enhancement point for a custom report?

1398


Do we create table fields with out data elements and domains?

885


Can we use transfer dataset to transfer data in internal table ?

1909


What are plan versions used for? : sap abap hr

812


What is the difference between a substructure and an append structure? : abap data dictionary

893


Name the function module used to convert logical file names to physical file names in abap/4 programs?

898


What is client in the sap system? : sap abap hr

821


What does hide statement do?

801


Can you assign a matchcode object to a parameter? If so how?

844


What are the screen elements.

780


Which one is better joins or views and why?

862