WAP to Calculate Area of Triangle Using Parmetrsied Constructor and Area Of Rectangle Using Copy Constructor?

class AreaExample
{
    int a,b;
    float area;
   AreaExample(int a,int b)
   {
      this.a=a;
      this.b=b;
   }
    AreaExample(AreaExample o)
   {
      this.a=o.a;
      this.b=o.b;
   }
 
   void areaTriangle()
    {
       area=(a*b)/2;
    }
    void areaRectangle()
    {
        area = (a*b);
    }
    public String toString()
    {
         return "Area is "+area;
    }
    public static void main(String args[])
    {
        AreaExample obj = new AreaExample(100,20);
        obj.areaTriangle();
        System.out.println(obj);
        AreaExample obj1 = new AreaExample(obj);
        obj1.areaRectangle();
        System.out.println(obj1);
    }

}

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post