Hi all,
i compiled the following code and it compiled but gave me a run time exception followed by the code
ERROR Inside O
I am a Dog
Add Animal
Added Animal
Exception in
thread "main" java.lang.ClassCastException
at o.main(o.java:29)
Questions 1) Why did it compile in the first place?
2) At runtime why Cast Exception, i am extending from Dog and casting o to it
3) if i change O = (o)dog to O = dog , it throws compile time error as follows :
found : Dog
required: o
O = dog;
^
1 error Why so???