Friday, 18 January 2013


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

Related Posts :



2 comments:

  1. can you please give some examples for programmes having function overloading and switch case combined?

    ReplyDelete
  2. can you please give some examples for programmes having function overloading and switch case combined?

    ReplyDelete