AREA RECTANGLE USING DEFAULT & PARAMETERIZED CONSTRUCTOR

//PROGRAM TO FIND AREA OF RECTANGLE USING DEFAULT AND PARAMETERIZED CONSTRUCTOR
class Rectangle
{
int ar,length,breadth;
Rectangle( )    //DEFAULT CONSTRUCTOR
{
length=10;
breadth=20;
}
Rectangle(int l, int b)  //PARAMETERIZED CONSTRUCTOR
{
length=l;
breadth=b;
}
void area( )        //CALCULATING AREA
{
ar=length*breadth;
System.out.println(” “+ar);
}
public static void main(String args[ ])
{
Rectangle r1=new Rectangle( );    //DEFAULT CONSTRUCTOR IS CALLED

Rectangle r2=new Rectangle(15,15);  //PARAMETERIZED CONSTRUCTOR
System.out.println(“Area of rectangle with default constructor is: “);
r1.area( );
System.out.println(“Area of rectangle with parameterized constructor is: “);
r2.area( );
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *