Originally posted by geetha nagarajan:
1.Legal at compile,fails at runtime.
p=d1;
2.Illegal at compile and runtime.
d1 =d2;
d1=(Derivedone)d2;
d1=(Derivedone)p;
3.Legal at compile time and runtime
p=(Parent)d1;
Did you try plopping it in a file and letting the compiler tell you what was legal or not??
1.Legal at compile,fails at runtime.
p=d1; WRONG -- it's both legal at compile time and at runtime, because DerivedOne
is-a Parent.
#3 is correct for the same reason, the explicit cast to type Parent is not necessary.
2.Illegal at compile and runtime.
d1 =d2;
d1=(DerivedOne)d2;
d1=(DerivedOne)p; CORRECT -- because the above do not have a
is-a relationship
[ June 03, 2002: Message edited by: Jessica Sant ]