Just to focus on the problem, the official answer given says that there is no ClassCastException at runtime.
I would think that there is and I'll explain why I think so. Line1 (ArrayList b = a) is taking an ArrayList<Circle> and assigning it to an ArrayList raw reference. That I can live with. The next line casts b to an ArrayList<Rectangle> and puts it into c, an ArrayList<Rectangle> reference. So I have taken what is actually an ArrayList<Circle> and stuffed it into an ArrayList<Rectangle> reference by casting it. Fine! I can see that would get through the compiler but, at runtime, I would think that the JVM would realize that the true type of b is an ArrayList<Circle> and throw a ClassCastException.
Okay..... what am I missing?
[ September 05, 2008: Message edited by: Bob Ruth ]
SCJP - 86% - June 11, 2009
when you write ArrayList<Circle> the compiler will remove the <Circle> from this statement. This is called type erasure. So actually the JVM doesn't know that you are assigning ArrayList<Circle> to ArrayList<Rectangle>. for the JVM they are just ArrayList. that's it, the JVM doesn't know about the type of the ArrayLists.