Function Overloading in JAVA

0
86

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 13 times – 330 B

Was this post helpful?
Let us know, if you liked the post. Only in this way, we can improve us.
Yes0
No0
Previous articleObject Declaration and Access Class Members in JAVA
Next articleHow to learn English Speaking?
An educational consultant Vineet Agrawal is a director and founder of Solution Center, Agra. He has been providing training for last 17 years. He has trained 1000s of students of the software industry. He has been actively involved in final year projects of B.Tech. (CS /IT). The programs included in this video series are based on his experience of teaching that will help you in cracking a java interview.

Leave a Reply