Say I have an abstract Animal class with an abstract method
public abstract Animal mateWith(Animal mate);
the problem is that if I subclass Snake and Armadillo, then such a call would be legal:
mySnake.mateWith(myArmadillo);
But I want the snakes to mate with the snakes. I need to define something like this:
public abstract Animal_Of_My_Class mateWith(Animal_Of_My_Class mate);
Is this possible in Java?
source share