You can not have two methods with the same signature, and the return is not part of the signature.
You could accomplish what you want using an interface as parent of Animal and Person. This will return an appropiate Person or Animal depending on what you pass as arguments. The return type of the method will be the Interface.
public interface Living {}
And:
public class Animal implements Living {}
For person:
public class Person implements Living {}
So your method will be:
public Living getEntity(Something e) {
// you can return Animal or Person
}
You will need to cast the return of getEntity
Animal myAnimal = (Animal)myClass.getEntity(...);
Another alternative will be to use generics (and you will avoid the casting), and have different instances of the class returning different types. One example (you could follow different strategies):
class Dynamic <T extends Object> {
T t;
T getEntity(Object e) {
return t;
}
void setEntity(T e) {
this.t = e;
}
}
And to use it:
Dynamic<Animal> animalStore = new Dynamic<>();
Dynamic<Person> personStore = new Dynamic<>();
So animalStore will return an Animal and personStore a Person.