mercredi 24 décembre 2014

Java - Overriding methods by passing as argument the subclass object where the supertype is expected


I am just learning Java. Not a practicing programmer. The book I am following says, that when overriding a method, the argument types must be the same, but the return types can be polymorphically compatible. My question is why cant the arguments passed to the overriding method not be a subclass type of the supertype expected. In the overloaded method, whatever method I call on the object is guaranteed to be defined on the object.





Aucun commentaire:

Enregistrer un commentaire