Firstly, since mammal is abstract, this would not be an override, rather an
implementation.But this is trivial to the question, I guess.
In case of overriding then
IMHO, I dont suppose this is legal. Although Dog Extends mammal,I dont suppose you can override
Mammal giveBirth() with
Dog giveBirth() in as far as overriding rules are concerned. A better, and legal implementation/override would be
class Dog extends Mammal{
public
Mammal giveBirth(){
return
new Dog();
}
}
So even if the return type is declared as mammal, we are allowed to return its subclass, inside dog.
Herbert