1)
Code:
public class Circle extends Shape{
double radius;
Circle(double radius){
this.radius=radius;
}
double calculateArea(){
return (22/7)*radius*radius;
}
}
public class Rectangle extends Shape{
private double width;
private double length;
Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
double calculateArea() {
return length * width;
}
}
public abstract class Shape{
abstract double calculateArea();
void sisplayShapeName(String name){
System.out.println("Shape:"+name);
}
}
public class Program {
public static void main(String[] args) {
Circle circle = new Circle(10);
circle.sisplayShapeName("Circle");
System.out.println("Area: " + circle.calculateArea());
Rectangle rectangle = new Rectangle(4, 6);
rectangle.sisplayShapeName("Rectangle");
System.out.println("Area: " + rectangle.calculateArea());
}
}
Output: