Wednesday, 27 January 2016

Java Tutorial : Java Runtime Polymorphism(version2)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=jAfw5OAZkmg&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java Runtime Polymorphism(version2)
Animal.java
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();     
    }

}
Output
I am a generic Animal.
I am a Dog.
I am a Lion.
I am a Tiger.
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/PolymorphismDemo_Runtime_V2_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/PolymorphismDemo_Runtime_V2_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/527ec09d8e1fd3cdfc42e1a5df2ff8d97e615036/BasicJava/PolymorphismDemo_Runtime_V2_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge