Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Wide casting

Former Member
0 Likes
762

Hi all,

Can anybody please tell the usuage of wide casting.

preferable with simple code.

Anirban Bhattacharjee

1 ACCEPTED SOLUTION
Read only

Former Member
4 REPLIES 4
Read only

Former Member
0 Likes
647

Hello anirban,

check this out...

[;

regards,

bhumika

Read only

Former Member
Read only

Former Member
0 Likes
647

Hi,

1. Wider/up casting :

This means a ref object used is of a parent. Now here technically speaking you can only call the methods of the parent class and not of the child class. Even if the parent object is referencing to a child object at runtime, the compiler does not allow you to call the child method.

Wide casting does not have run-time errors as the compiler is able to identify the error at compile time only.

Wide casting is helpful when you want to have a generic parameter as the importing parameter in OOPs.

For eg.

Class p1

{

method x.

}

Class c1 parent p1

{

method y.

}

Class c2 parent p1

{

method z.

}

In the above example both class c1 and c2 are subclasses of p1 and therefore has method x.

Now let us say the user at runtime can pass object of c1,c2 or p1 and method x has to be capable of receiving all these, then in such case you can assign reference object of parent to method x.

So method x can be defined as follows

Class p1

{

method x importing p -


> where p is type ref to p1.

}

I hope this explains your query.

Regards,

Saurabh

Read only

Former Member
0 Likes
647

Thank all.

i have got the concept.

Anirban Bhattacharjee