Java

Java - Method Overloading

Java - Method Overloading
class OverloadDemo

{

  void area(float x)

    {   

       System.out.println("\nthe area of the square is "+Math.pow(x, 2)+" sq units");   

    }

  void area(float x, float y)

    {

        System.out.println("\nthe area of the rectangle is "+x*y+" sq units");   

    }

    void area(double x)

    {

        double z = 3.14 * x * x;

        System.out.println("\nthe area of the circle is "+z+" sq units");   

    }

}

class Overload1

{

     public static void main(String args[])

            {

               OverloadDemo ob = new OverloadDemo();

               ob.area(5);

               ob.area(11,12);

               ob.area(2.5);

        }

}
Senthilvelan Sambamoorthy

Senthilvelan Sambamoorthy is working as a Professor in Department of Master of Computer Applications, Paavai Engineering College, Namakkal, Tamilnadu, India, He is Masters in Computers Applications. Having 18+ years of experience and his area of interest is Java, JSP, Servlet, J2EE, C#, PHP, Python ASP.NET, SQL Server and etc.