Click here to watch in Youtube :https://www.youtube.com/watch?v=rttH7OiM7SE&list=UUhwKlOVR041tngjerWxVccwClick the below Image to Enlarge |
Java Tutorial : Java Polymorphism(version3) |
|
Java Tutorial : Java Polymorphism(version3) |
|
Java Tutorial : Java Polymorphism(version3) |
|
Java Tutorial : Java Polymorphism(version3) |
|
Java Tutorial : Java Polymorphism(version3) |
|
Java Tutorial : Java Polymorphism(version3) |
Animal.java public class Animal
{
public void makeNoise()
{
System.out.println("Some sound.");
}
}
class Lion extends Animal
{
public void makeNoise()
{
System.out.println("Roar.");
}
}
class Dog extends Animal
{
public void makeNoise()
{
System.out.println("Bark.");
}
}
PolymorphismTest.java public class PolymorphismTest
{
public static void main(String[] args)
{
Animal animalRef = new Lion();
animalRef.makeNoise();//Prints Roar.
animalRef = new Dog();
animalRef.makeNoise();//Prints Bark.
}
}