Write a Java program that displays area of different Figures(Rectangle,Square,Triangle) using the method overloading.

/*Write a Java program that displays area of different Figures(Rectangle,Square,Triangle) using the method overloading.*/
class M_overloading
{
    float h,l;
    int base,hight;
     float area(float l)
      {return(l*l);}
    float area(float h,float l)
     {return(h*l);}
    double area(int hight, int base)
      {return(0.5*hight*base);}
}
  class M_overloadingdemo
    {
       public static void main(String []args)
        {
           M_overloading a= new M_overloading();
          double ans= a.area(2);
       System.out.println("area of squer="+ ans);
            ans =a.area(2,5);
      System.out.println("area of rectangel="+ ans);
            ans= a.area(2,3);
       System.out.println("area of  triangle="+ ans);
  }
}
     
    

Comments

Popular posts from this blog

Write a java program to calculate gross salary & net salary taking the following data

WAP a program that illustrates interface inheritance. Create two interface p1 and p2 . create Interface p which extends p1 and p2 and then create interface p12 which extends p12. Each interface declare one constants and one method. Create class Q which implements p12 and define all the methods of interface which displays value of constants

Example of abstract class