C:\JAVA>javaTest true java.lang.ClassCastException: Base java.lang.ClassCastException: Base true Here I am unable to understand the output the class cast exception with Base two times and then true why? Please explain this. thanks in advance payal [This message has been edited by payal sharma (edited July 27, 2001).]
The two exceptions for base are: Cloneable c1=(Cloneable)x; Cloneable c2=(Cloneable)x; When called with base. Since all objects extends Object, Test will always print "true" when called with an object (both base and child are objects). Since base implements runnable and child extends base, the cast to runnable will work for both. Child implenets colneable, so the above cast will work for it. Dow this explain it? /Mike
when x is an instance of Base class. When x is a instance of Child class, the above statements would not give ClassCastException , since Child class implements Cloneable. When either of the constructors are invoked, each being an instanceof the Object prints true in the output. Hope this helps, Sandeep SCJP2, OCSD(Oracle JDeveloper), OCED(Oracle Internet Platform)
Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad: