I came across this problem while
testing out covariant return types
The output to the above is
Returning Car
Returning CarInVehicle
vehicleCar 3
vehicleCar2 3
I was suprised to see 3 on both occassions. I was expecting 5 for both because i knew that at runtime the JVM will look at the actual object but this doesnt seem to be the case.
Does this mean that methods can be overriden but fields work the same way as overloading a method? I cant find this described anywhere in the book.
Thanks