Suyash Gulati wrote:can anyone specify the rules(all) for casting. like when we should cast explicitly n when not or when it will be a compile time error or a RuntimeException.
(I wrote all because every time i attempt a question about casting i get to know something different OR probably i am getting a bit confused)
Sergej Smoljanov wrote:
always get compiler error because you can`t assign to reference of type Child, reference variable of type Parent
Sergej Smoljanov wrote:try it ;)
or you cast down and actual object is not subtype of type (to which you cast) you will get ClassCastExeption.
Suyash Gulati wrote:but why? p refer to an object of type Child. it should compile, no? :/
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |