ankur trapasiya wrote:
in line 4
c=(C) new Serializable();
here you are trying to instantiate Serializable interface and which is not legal so it is showing compiler error..
but i am also confused here in line 2
d=(D)ob;
The image is not much visible to me but I don't think that line is c = (C) new Serializable()
I think that is
c = (C)new Serializable(0{}; // this is different from above one, this is inner anonymous class
// and you will study this in the 8th chapter
now the second question is about casting the Object into D
this is valid as at compile time we can cast to anything across the same hierarchy,
and D extends Objects
so this is possible
SCJP 6 [86%], OCPWCD [84%], OCEJPAD [83%]
If you find any post useful, click the "plus one" sign on the right