Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Method Overloading in Java

    • 0
    • 3
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 498
    Comment on it

    Method Overloading

    Creating a multiple methods with same name and with different argument list is known as method overloading.

    When we are overloading a method argument, list should be unique i.e, it should be unique with either number of arguments or type of an argument.

    We use overloading when we have a same functionality for different data types.

    When a overloaded method is called, a particular method will be invoked based on data's passed.

    Example of Method Overloading:

    Class Run
    {
    public static void main(String[] args)
    {
    System.out.println("Program Starts");
    System.out.println(add(13.456,12.123));
    System.out.println(add(10,30));
    System.out.println(add(12,15.345));
    System.out.println("Program end");
    }
    static int add(int n1, int n2)
    {
    return n1+n2;
    }
    static double add(int n1, double n2)
    {
    return n1+n2;
    }
    static double add(double n1, double n2)
    {
    return n1+n2;
    }
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: