class Animal { }
class Horse extends Animal { }
class UseAnimals {
publicvoid doStuff(Animal a) {
System.out.println("In the Animal version");
}
publicvoid doStuff(Horse h) {
System.out.println("In the Horse version");
}
publicstaticvoid main (String [] args) {
UseAnimals ua = new UseAnimals();
Animal animalObj = new Animal();
Horse horseObj = new Horse();
ua.doStuff(animalObj);
ua.doStuff(horseObj);
}
}
Remember, the reference type determines which overloaded method is invoked!