JAVA METHOD OVERLOADING

 
The Java programming language supports overloading methods, and Java can distinguish   between methods with different method signatures.
More than one method have same name but different type of argument or different no. of arguments available in same class or it subclass is called overloading.
Return type of method and Access Specifiers of method is not a problem in method overloading.
 

Example of method overloading 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Overload
{
    void test(int a)
    {
        System.out.println("a: " + a);
    }
    void test(int a, int b)
    {
        System.out.println("a and b: " + a + "," + b);
    }
    double test(double a)
    {
        System.out.println("double a: " + a);
        return a * a;
    }
}
class MethodOverloading
{
    public static void main(String args[])
    {
        Overload overload = new Overload();
        double result;
        overload.test(10);
        overload.test(10, 20);
        result = overload.test(5.5);
        System.out.println("Result : " + result);
}

O/P:

java overloading methods