Function Overloading in JAVA

0
212

You can create more than one functions with the same name in a java class if their signatures are different.

Look at the 3 different variants of add() functions in the source code given below.

 

class fun_Overload
{
	int add(int a, int b)
	{
		return a+b;
	}
	int add(int a, int b, int c)
	{
		return a+b+c;
	}
	String add(String s1, String s2)
	{
		return s1+s2;
	}
	public static void main(String args[])
	{
		fun_Overload fov=new fun_Overload();
		System.out.println(fov.add("Learn By", " Watch"));
		System.out.println(fov.add(2,3));
		System.out.println(fov.add(2,3,4));
	}
}

Download “Download Function Overload Source Code” fun_overload-1.zip – Downloaded 37 times – 330 B

How's this tutorial?
Easy0
Difficult0

LEAVE A REPLY

Please enter your comment!
Please enter your name here