# Calculate area of rectangle using class in java

Let’s learn to calculate area of rectangle using class in java.

## Calculate area of rectangle using class in java

To calculate area of rectangle in java,

• first create class “RectangleShape”. This class has two integer variables length, breadth.
• to set values for variables length and breadth setValue() method is created.
• In findArea() method we are calculating area of rectangle and in turn returning area.
• In the main() method create object of class RectangleShape.
• assign values for length and breadth. Finally calculate area by calling findArea() method.

Here’s java program to find the area of rectangle using class and object.

```// calculate area of rectangle using class in java
import java.io.*;
class RectangleShape
{
void setValue(int l, int b)
{
length = l;
}
// get area of rectangle
int findArea()
{
}
}
{
public static void main(String[] args)
{
RectangleJava obj = new RectangleJava();
obj.setValue(10, 5);
System.out.println("Area of rectangle: " + obj.findArea());
}
}

```

Output:

Area of rectangle: 50

Also read – find area of rectangle in java using method

Program to find area of rectangle using inheritance in java

```class RectangleDimension
{
int length;
}
class Rectangle extends RectangleDimension
{
int area;
void findArea()
{
}
}
public class AreaOfRectangleUsingInheritance
{
public static void main(String[] args)
{
Rectangle obj = new Rectangle();
obj.length = 50;
obj.findArea();
int area = obj.length * obj.breadth;
System.out.println("Area of rectangle is: " + area);
}
}

```

Output:

Area of rectangle is: 1000

Also read – java program to calculate area of rectangle