Skip to content

Program to Demonstrate Method Overloading in Java (BlueJ)

Program to Demonstrate Method Overloading in Java (BlueJ)

Code:

/***** PROGRAM TO DEMONSTRATE METHOD OVERLOADING *****/
public class methodOverloading
{
    public static void main()
    {
        int num1 = 10, num2 = 20;
        float num3 = 10.10f;
       
        methodOverloading call = new methodOverloading();
       
        call.add(num1, num2);
        call.add(num1, num2, 30);
        methodOverloading.add(num1, num3);
        add(30.30f, num2);
       
    }
    public static void add(int no1 , int no2)
    {
        System.out.println(“Addition of “+no1+ ” and “+no2+ ” ==> “+(no1+no2));
    }
    public static void add(int no1 , float no2)
    {
        System.out.println(“Addition of “+no1+ ” and “+no2+ ” ==> “+(no1+no2));
    }
    public static void add(float no1 , int no2)
    {
        System.out.println(“Addition of “+no1+ ” and “+no2+ ” ==> “+(no1+no2));
    }
    public static void add(int no1 , int no2, int no3)
    {
        System.out.println(“Addition of “+no1+ ” + “+no2+ ” + “+no3+” ==> “+(no1+no2+no3));
    }
   
}

OUTPUT:
Addition of 10 and 20 ==> 30
Addition of 10 + 20 + 30 ==> 60
Addition of 10 and 10.1 ==> 20.1
Addition of 30.3 and 20 ==> 50.3

2 thoughts on “Program to Demonstrate Method Overloading in Java (BlueJ)”

Leave a Reply to Addri Dasgupta Cancel reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!