Roy Pozarelli wrote:Since the point of the example is to show 2 unrelated classes can't be cast to each other.
As written, of course the code won't compile but not for the reason listed.
From the code snippet you would expect that it doesn't compile for another reason, but when you try to compile this code snippetyou'll get exactly the same reason listed in the paragraph (incompatible types)So against all odds, the study guide is actually spot-on!
Roy Pozarelli wrote:Should the DOES NOT COMPILE line be:
Bird bird = (Bird) fish;
But I agree it would make more sense and be much more obvious, if the code snippet tries to cast the reference variable fish to Bird. Because with the current code snippet you might think it doesn't compile because the reference variable bird may not have been initialized (and the first line of the main method is redundant). So the statementshould be changed toAnother alternative could be this main method