abstract class Figure {
double length;
double width;

// Constructor
public Figure(double length, double width) {
this.length = length;
this.width = width;
}

// Abstract method to compute the area
abstract double computeArea();
}

class Rectangle extends Figure {

// Constructor
public Rectangle(double length, double width) {
super(length, width);
}

// Override method to compute the area of the rectangle
@Override
double computeArea() {
return length * width;
}
}

public class RectangleAreaCalculator {
public static void main(String[] args) {
// Example usage:
Rectangle rectangle = new Rectangle(10, 5);
System.out.println(“Area of Rectangle: ” + rectangle.computeArea());
}
}


Leave a Reply

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