About me

Gladson A
Software Engineer,Chennai.

Translate

Pages

Saturday 30 June 2012

Method Overloading in JAVA


Method Overloading in JAVA

-Methods of same name can be declared in java in the same class,they have different set of parameters(number ,types,order of parameters).


-When an overloaded method method is called,JAVA compiler identify the appropiate method by using the parameters and it types,numbers and order of the arguments. 

program:

public class methodoverload { public static void main(String[] a)

{
int i=123; int j=13;
double d=13.9;

func();
func(i);
func(i,d);
func(d,i);
func(59,4,"gkads");

}

public static void func()

{
System.out.print("func\n");

}

public static void func(int i)

{
System.out.printf("func with one parameter:%d\n",i);

}

public static void func(int i,double d)

{
System.out.printf("func with two parameters order1:%d%10f\n",i,d);

}

public static double func(double d,int i)

{
System.out.printf("func with two parametrs order2:%f%10d\n",d,i);

return 0;

}

public static void func(double d,int i,String s)

{
System.out.printf("func with three parameters order1:%f%10d%10s\n",d,i,s);

}

public static void func(int j,int i,String s)

{
System.out.printf("func with three parameters order2:%d%10d%10s\n",j,i,s);

}




}

output:

func
func with one parameter:123
func with two parameters order1:123 13.900000
func with two parametrs order2:13.900000       123
func with three parameters order2:59         4     gkads


Ask your forums and question in the comment box(mention your mail ID).


0 comments:

Post a Comment