Originally posted by victor kamat: ...My understanding of generics is that the object returned by lis.get(1) is cast to A by the JVM. So why am I not seeing "A" output...
The reference is cast to type A, but the true runtime type of the object remains B. Does that make sense?
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Jan 10, 2007
Joined: Dec 15, 2006
Here, the subclass B is overriding the toString() method defined in the class A. Thus according to the overriding rules, the invocation of toString() method on the B object(with A's reference) will invoke the B's method. If you had removed the toString() method from B then you would have got 'A' as the output.