Thursday, December 04, 2003

Type Casting ??

i wanted to ask how does type casting objects work? wrt in java/c#.
suppose i add String instances to a collection. as a collection returns Object i then typecast the return objects to String.
public Object get(int index);
this is the signature/prototype for the method to return an object. which is then typecast to String object by (String)get(index);
my basic doubt is that like in polymorphism, the derived class knows about its parent,.. which is obvious. but for something like type casting the parent class has to know who is the derived instance. if one of you could provide a clearer explanation it would be great. do you know of anything like v-tables in java/c#.

No comments: