2) true
1) when Animal a = new Dog(); it runs.
Originally posted by Badal Chowdhary:
Hi All,
I have a doubt in reference variable casting.
Assume Dog extends Animal.
1) Is it true that the second statement will compile but not run:
In other words is it safe to believe that, whenever we are down-casting, the program will always compile but never run?
2)
For up-casting is it safe to believe that, it will always compile and run fine.
Are there any special cases where up-casting can cause compilation or run problems?
Thanks
Regards,
Badal Chowdhary