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

Ratings

  • Rate this
  • Summary
Current Average Ratings
Cognitive
Avg: 0/5
Affective
Avg: 0/5
Function Overloading in JAVA
Total Avg Rating: 0.00 out of 5 with based on 0 rating(s)
Cognitive
Affective
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