Thursday, 21 January 2016

Java Tutorial : Java method overloading vs method overriding(version1)


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

Click the below Image to Enlarge
Java Tutorial : Java method overloading vs method overriding(version1) 
Java Tutorial : Java method overloading vs method overriding(version1) 
MethodOverridingExample.java
class Animal
{
    public void eat()
    {
        System.out.println("Animal is eating...");
    }
}

class Lion extends Animal
{
    public void eat()
    {
        System.out.println("Lion is Eating meat...");
    }
}

public class MethodOverridingExample
{
    public static void main(String args[])
    {
        Animal animalRef = new Lion();
        animalRef.eat();
    }
}
Output
Lion is Eating meat...
OverloadingExample.java
public class OverloadingExample
{

    public void add(int a, int b)
    {
        int total = a + b;
        System.out.println("total : " + total);
    }

    public void add(int a, int b, int c)
    {
        int total = a + b + c;
        System.out.println("total : " + total);
    }
    
    public static void main(String args[])
    {
        OverloadingExample overloadingExample= new OverloadingExample();
        
        //Call two parameter add method
        overloadingExample.add(2,2);
        //Call three parameter add method
        overloadingExample.add(5, 5, 5);        
    }

}
Output
total : 4
total : 15
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/MethodOverridingDemo_version1-App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/MethodOverridingDemo_version1-App

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