Casting a child class into a parent class.
Hi there, new to the forums and plan on staying for a very very long time. :o
My question, as the title states:
-Is it possible to cast an object of a child class into an object of its parent class and if so, how is it coded?
This is what I've been tinkering with thus far..
Example:
ChildClass a = new ChildClass();
ParentClass b = (ChildClass)a;
-Unsub
Casting related to inheritance
Here by i give the casting procedures and problems,related to inheritance
superclass=subclass (This is valid)
subclass=(subclass)superclass (This is valid at compile time but shows an error in run time-ClassCastException)
subclass=superclass (Shows error in compile time itself)