Write a Java program to calculate the area of rectangle using parameterized constructor. - Code

Latest

programs

Sunday, October 30, 2011

Write a Java program to calculate the area of rectangle using parameterized constructor.


  1. Write a program to calculate the area of rectangle using parameterized constructor.
class Rectangle
{
      int length;
      int width;
      Rectangle(int x,int y)
      {
                  length=x;
                  width=y;
      }
      int rectArea()
      {
                  return(length*width);
      }
}

class RectangleArea
{
      public static void main(String args[])
      {
                  Rectangle rect1=new Rectangle(15,10);
                  int area1=rect1.rectArea();
                  System.out.println("Area1="+area1);
      }
}

2 comments: