by Dinesh Thakur

When in a class, we have more then one method with similar name but with different type signatures i.e. with different number of parameters or with different types of parameters, then we say that the method is overloaded. Compiler will recognize which method to execute on the basis of the type and number of parameters used while calling the method.

class Rectangle

          {
              int length,breath,a;
              void getData(int x,int y)
                 {
                     length=x;
                     breath=y;
                 }
                     void getData(int x)
                      {
                          length=x;
                          breath=15;
                       }
                          void getData()
                            {
                                length=60;
                                breath=15;
                            }
                                int getArea()
                                   {
                                       a=length*breath;
                                       return(a);
                                    }
           }
                     class FunctionMethod
                        {
                             public static void main(String args[])
                               {
                                   Rectangle Rect = new Rectangle();
                                   Rectangle Rect1 = new Rectangle();
                                   Rectangle Rect2 = new Rectangle();
                                   Rect.getData();
                                   Rect1.getData(30);
                                   Rect2.getData(40,60);
                                   System.out.println("Area of First Rectangle is : "+Rect.getArea());
                                   System.out.println("Area of Second Rectangle is : "+Rect1.getArea());
                                   System.out.println("Area of Third Rectangle is : "+Rect2.getArea());
                                }
                       }

Function Overloading and Method Overloading