Overloading in Java Programming

Overloading in Java Programming

Previous Home Next

 

In Java it is possible to define two or more methods within the same class that share the same name,
 as long as their parameter declarations are different.

When this is the case,the methods are said to be overloaded,  and the process is referred to as method overloading. Method overloading is one of the ways that Java implements polymorphism.
 


 
class Overload
void test()
{
System.out.println("No parameters");
}

void test(int a, int b)
{
System.out.println("a and b: " + a + " " + b);
}

void test(float a)
{
System.out.println("Inside test(double) a: " + a);
}
}
class Overload1
{
public static void main(String args[])
{
Overloading ob = new Overload();
int i = 100;
ob.test();
ob.test(10, 20);
ob.test(i);
ob.test(586.2);
}
}


Previous Home Next