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

when run my program in se38 it was showing output, when i take background execution and giving printer details it was shoing out put. but in SP01 when i give the Spool Request Number it was showing not yet processed entire page why it happens i dont know please give me a solution.

2327


Can you create an internal table dynamically?(at run time)

1603


Explain the properties of selection screen?

835


How do you validate the selection criteria of a report? And how do you display initialvalues in a selection screen?

838


Explain the advantages and disadvantages of abap query tool?

691






How many types of buffering? : abap data dictionary

900


Explain what is an rdbms?

762


What are the differences between the table and the structure in the data dictionary in the sap abap?

781


SM35 transaction, How to automate BDC ?

820


Explain the difference between a pool table and a transparent table?

719


What are the basic functions of database utility? : abap data dictionary

808


What are the components of selection table?

788


How is conversion of data types done between abap/4 & db layer?

831


Which one is better joins or views and why?

810


What is static attribute

1263