Categories
Uncategorized

CIA 1A

Example: Constructor and Method Overloading

class consfun

{

double length,breadth,radius;

consfun(double r);

     {

        radius=r;

      }

consfun(double l,double b)

     {

       length=l;

       breadth=b;

     }

void area1()

   {

       double area;

       area=3.14*radius*radius;

       System.out.println(“Area of Square:”+area);

    }

void area1(double h)

   {

       double area;

       area=0.5*(length+breadth)*h;

       System.out.println(“Area of Trapezium:”+area);

   }

}

class area

{

public static void main(String args[])

    {
        consfun c=new consfun(2);
        consfun c1=new consfun(3,6);
        c.area1();
        c1.area1(4);
      }

}

One reply on “CIA 1A”

Comments are closed.