aa's reference type is
A, and it's that that matters as far as the compiler is concerned. So the compiler things the return type on line 8 is
Object. So it needs casting to
String.
Polymorphism happens at runtime, which is why a
String is returned and the cast works.