Friday 15 January 2016

Java Tutorial : Java method overriding(Animal)



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

Click the below Image to Enlarge
  Java Tutorial : Java method overriding(Animal)
  Java Tutorial : Java method overriding(Animal)
Animal.java
public class Animal
{
    public void eat()
    {
        System.out.println("Animal is eating");
    }
}
Lion.java
public class Lion extends Animal
{
    @Override
    public void eat()
    {
        System.out.sprintln("Lion is eating meat");
    }
}
Cow.java
public class Cow extends Animal
{
    @Override
    public void eat()
    {
        System.out.println("Cow is eating grass");
    }
}
MethodOverrideTest.java
public class MethodOverrideTest
{

    public static void main(String[] args)
    {
        Animal animalRef = new Lion();
        animalRef.eat();

        animalRef = new Cow();
        animalRef.eat();
    }

}
Output
Lion is eating meat
Cow is eating grass
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/MethodOverridingDemo-Lion-Cow-App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/MethodOverridingDemo-Lion-Cow-App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/fa67e02bcd9efeae1c2ea3019677c5252e4db5f7/BasicJava/MethodOverridingDemo-Lion-Cow-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