to create an abstract class named shape that contains two integers and an empty method named printArea(). Provide three classes named Rectangle, Triangle and Circle such that each one of the classes extends the class Shape. Each one of the classes contains only the method printArea() that prints the area of the given shape

PHOTO EMBED

Sun Mar 23 2025 10:00:47 GMT+0000 (Coordinated Universal Time)

Saved by @Vyshnaviii

abstract class Shape 
{
 int dimension1;
 int dimension2;
 abstract void printArea();
}
class Rectangle extends Shape 
{
 void printArea() 
 {
 System.out.println("Area of Rectangle: " + (dimension1 * dimension2));
 }
}
class Triangle extends Shape 
{
 void printArea() 
 {
 System.out.println("Area of Triangle: " + (0.5 * dimension1 * dimension2));
 }
}
class Circle extends Shape 
{
 void printArea() 
 {
 System.out.println("Area of Circle: " + (Math.PI * dimension1 * dimension1));
 }
}
class ShapeArea 
{
 public static void main(String[] args) 
 {
 Rectangle rectangle = new Rectangle();
 rectangle.dimension1 = 5;
 rectangle.dimension2 = 4;
 Triangle triangle = new Triangle();
 triangle.dimension1 = 8;
   triangle.dimension2 = 6;

 Circle circle = new Circle();

 circle.dimension1 = 10;

 rectangle.printArea();

 triangle.printArea();

 circle.printArea();

 }

}
content_copyCOPY