The me
method is returning a reference to the actual object, which is of the type Child
, but the type of the reference is of the type Parent
.
So, what you have is a reference of the type Parent
that points to an object of the type Child
. You can use that to access any members that the Child
class inherits from the Parent
class. To access the members of the Child
class you have to cast the reference to the type Child
:
Child c = (Child)someObject.me();
You could make the me
method return a Child
reference and do the casting inside the method, but then it will of course not work to return a reference to a Parent
object. If you don't use generics, each method can only have one return type. Even if you override the method in the Child
class, it still has to return the same data type as in the Parent
class.