class Animal
{
void whoAmI()
{
System.out.println("I am a generic Animal.");
}
}
class Dog extends Animal
{
void whoAmI()
{
System.out.println("I am a Dog.");
}
}
class Lion extends Animal
{
void whoAmI()
{
System.out.println("I am a Lion.");
}
}
class Tiger extends Animal
{
void whoAmI()
{
System.out.println("I am a Tiger.");
}
}
RunTimePolymorphismDemo.java public class RunTimePolymorphismDemo
{
public static void main(String[] args)
{
Animal animalRef = new Animal();
animalRef.whoAmI();
animalRef = new Dog();
animalRef.whoAmI();
animalRef = new Lion();
animalRef.whoAmI();
animalRef = new Tiger();
animalRef.whoAmI();
}
}