How to type casting in OOPS ABAP and ABAP ?

Answer Posted / rs agarwal

1. Narrow casting

2. Wide casting

Demo on "Narrow Casting" Parent class->M1 , Child class-
>M1,M2
Attributes of super class can only be accessed.
Methods defined at Super class(M1) can only be accessed.
Methods with REDEFINED Logic(M1) will be called
Methods in child class (M2) cannot be accessed
Demo on "Wide Casting" Parent class->M1 , Child class->M1,M2
Assign address of PARENT to CHILD Class object
Methods defined at child class(M2) can also be accessed
with Parent reference.
Methods with REDEFINED Logic (M1) will be called
The cast is only possible if the object was instantiated as
the child and then it was casted to the parent object and
then back again to the child object. The child has
everything the parent has so there is no problem with this
path.

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the last entry in all bdc tables? : abap bdc

763


What is payroll area

1982


What is the lock object?

769


Can we write the code both call transaction and session method in single program?

818


In Table Field when display the Name, whose first charecter should be capital letter and rest will be small letter.

1795






what comes in Timkein written test I hope some body can tell me at this id plz tell it before 9 pm 19 march

1884


Setting up a BDC program where you find information from?

861


in bdcsome times we get the ok code for "enter" wrongly instead of '/00'.what is the reason.how we can exceed this problem.

1952


What are the functional areas, user groups? How does abap query work in relation to these?

796


What are the different types of parameters? : abap modularization

823


Does sap handle multiple currencies?

773


What is the role of ‘refresh’ in internal table?

755


What is a collect statement?

747


Tell me a scenario where did you use secondary index?

800


How to create any functions? How to go about it?

761