Parameterized Method Overloading using Java



Write a program in Java to the use of Parameterized Method
Overloading.





Program:





class
Area


 {


  double CalArea(double r)


    {


      float pi=3.141f;


      return(pi*r*r);


    }


  double CalArea(double l, float b)


    {


     return (l*b);


    }


  double CalArea(float base, double height)


   {


    return(0.5*base*height);


   }


 }


class
Sk08


 {


  public static void main(String args[])


   {


    Area obj1=new Area();


    double a1= obj1.CalArea(5.5,6.5f);


    System.out.println("Area of Rectangle=
"+a1);





    Area obj2=new Area();


    double a2= obj2.CalArea(5.5f,6.5);


    System.out.println("Area of Triangle=
"+a2);





    Area obj3=new Area();


    double a3= obj3.CalArea(5.5);


    System.out.println("Area of Circle=
"+a3);


    }


 }


Compile:


D:\>javac
Sk08.java


Run:


D:\>java
Sk08


Output:


Area of
Rectangle = 35.75


Area of
Triangle = 14.625


Area of
Circle = 95.01525098085403










0 Comments