Monday , July 13 2020
Home / Java / JAVA #20 – Method Overloading in Java

JAVA #20 – Method Overloading in Java


Methodoverloading in Java

In some programming languages, function overloading or method overloading is the ability to create multiple methods of the same name with different implementations in same class.

Syntax

public class DataArtist {
   ...
   public void draw(String s) {
       ...
   }
   public void draw(int i) {
       ...
   }
   public void draw(double f) {
       ...
   }
   public void draw(int i, double f) {
       ...
   }
}
//File name FunctionOverloading.java
package functionoverloading;
public class FunctionOverloading {
    public static void main(String[] args) {
        Display objDis = new Display();
        objDis.Dis("Ali");
        objDis.Dis(2334.34534535567);
        objDis.Dis(123);
        objDis.Dis(18, "Ali");
        
    }  
}
// File name Display.java that store in Package folder
package functionoverloading;
public class Display {    
    public void Dis(String s)
    {
        System.out.println("The String Value Is: "+s);
    }
    public void Dis(double d)
    {
        System.out.println("The Double Value Is: "+d);
    }
    public void Dis(int i)
    {
        System.out.println("The Integer Value Is: "+i);
    }
    public void Dis(int i, String s)
    {
        System.out.println("The Id Is:"+i+" The Name  Is: "+s);
    }    
}

 

About Faheem

An adaptable and responsible Software Engineer, who enjoys working with computers and the opportunity to learn new skills and work with new technologies is particularly attractive to me.

Check Also

JAVA #32 – Java application using SQL server (Part: 01)

  In this part we made the GUI front end of a Application.

Leave a Reply

Your email address will not be published.