Function overloading (or) Method overloading:

Function overloading means "Having same function name for multiple methods with different signature". Or "Multiple methods with with same name but different signatures".
Different signature means 1. Having different number of parameters (or) 2. Having different types of parameters (or) 3. Having different order of parameters. Note: return type is not part of signature.
Two functions having same name, same signature, but with different return type is not considered as overloading. It is a compile time error.
Now lets see how to solve above problem by using function overloading concept:
File name : MainClass.java
       class Math
        {
	  public void add(int i,int j)
	  {
		System.out.println(i+j);
	  }
	  public void add(String s,String t)
	  {
		System.out.println(s+t);
	  }
         }
          public class MainClass
          {
	  public static void main(String[] args)
	    {
	      Math m=new Math();
	      m.(3,4);
	      m.add("hello","Bye");
	   }
        }

polymorhism
1) Overloading is an example of polymorphism.
2) It is polymorphism because based on the no. of parameters (or) type of parameters (or) order of parameters, it will call different function definitions, with same function name.
3)Overloading is an example of compile time polymorphism because the link between function definition and function call will be done at compile time.
The below is not an overloading:
class Math
 {
   public void add(int i,int j)
   {
     -----------
   }
   public void add(int j,int i)
   {
     -----------
   }
}
Because both methods have same signature.


This is an example of overloading:


exampleofoverloading
Example:

Below is not overloading. We can't judge function call based on return type.


Note: Overloading occurs in same class. Below program is not overloading.
          class Test
          {
 	   public void disp()
 	   {
  
   	    } 
          }
	  class Next
          {      
	  public void disp(int i)  //event hough the signature is diff but they are not  
                                     //in same class.
 	   {

	    }
 	  }

Constructor Overloading:

Since constructor is also a special kind of function, we can overload constructors also just like any other function. Having multiple constructors in a class with different signature is called as constructor overloading.
Program:

Find area of a rectangle and Square. Use constructor overloading in this example. If user passes only one value then we have to understand that it is for square. If user passes 2 values then it is for rectangle as rectangle will have both length and breadth.

rectangle and Sqaure
File name : MainClass.java

Below program is an example of constructor overloading

.
        class RectSQ
        { 
	int len,bred;
	public RectSQ(int l)
	{
		len = l;
		bred = l;
	}
	public RectSQ(int l,int b)
	{
		len =l;
		bred = b;
	}
	public void findArea()
	{
		System.out.println(len*bred);
	}
        }
           public class MainClass
            {
	       public static void main(String[] args){
		RectSQ s=new RectSQ(4);//this is square
		s.findArea();
		RectSQ r= new RectSQ(5,4);//this is rectangle
		r.findArea();
	     }
       }