To define the same name method for more than one time in one class with same signature and different arguments this concept is called as method overloading.


Write a program to define methods overloading.
1234567891011121314151617181920212223class over
{
void fun1
{
System.out.println("No argumented method");
}
void fun1(int x)
{
System.out.println("X is "+x");
}
void fun1(int a,int b)
{
System.out.println("A is "+a+" B is "+b);
}
public static void main(String args[])
{
over o=new over();
o.fun1();
o.fun1(10);
o.fun1(10,20);
}
}
Post A Comment: