Suppose classes Square and Rectangle extend class Shape.
Which statements are true regarding the following code?
1. Rectangle g = new Rectangle();
2. Shape c = (Shape)g;
3. Square lem = (Square)c;
A, C.
Line 2 is an assignment from a subclass to a superclass, so the cast is not necessary.
Line 3 compiles because it obeys the compile-time casting rules.
At runtime, the JVM notices that the class of the object referenced by c is not compatible with the Square class, so an exception is thrown.