Overriding and Overloading Example..

.. with inheritance!

This is the code I have:
public class Animal {}
public class Lion extends Animal {}
public class AnimalTamer {
    public void tameAnimal(Animal animal) {
        System.out.println("Animal tamer taming animal..");
    }
}
public class LionTamer extends AnimalTamer {
 
    // Looks like an overriding method, but really just overloading..
    public void tameAnimal(Lion lion) {
        System.out.println("Lion tamer taming lion..");
    }
 
    @Override
    public void tameAnimal(Animal animal) {
        System.out.println("Lion tamer taming animal..");
    }
}

and a little test code:
public class TestClass {
 
    public static void main(String[] args) {
        final Animal animal = new Animal();
        final Lion lion = new Lion();
        final Animal confusedLion = new Lion();
 
        final LionTamer lionTamer = new LionTamer();
        lionTamer.tameAnimal(animal);
        lionTamer.tameAnimal(lion);
        lionTamer.tameAnimal(confusedLion);
 
        // What if there is no reference?
        lionTamer.tameAnimal(new Animal());
        lionTamer.tameAnimal(new Lion());
    }
}

Can you guess the output?
Lion tamer taming animal..
Lion tamer taming lion..
Lion tamer taming animal..
Lion tamer taming animal..
Lion tamer taming lion..

In a nutshell..

Lion tamer seems to care about the type of the reference, not the concrete class of the object you are calling the tameAnimal method with. This was not so difficult..