package test;
import java.math.*;
abstract class Shape{
String color;
public abstract double area() ;
public abstract String toString();
public abstract String getColor();
public Shape(){
System.out.println("Shape constructor called");
}
}
class Circle extends Shape{
String color;
double radius;
public Circle(String color,double radius) {
this.color=color;
this.radius=radius;
System.out.println("Circle constructor called");
}
public double area() {
return radius*radius*Math.PI;
}
public String toString() {
return "Circle constructor called";
}
public String getColor() {
return color;
}
}
class Rectangle extends Shape{
String color;
double length;
double width;
public Rectangle(String color,double length,double width) {
this.color=color;
this.length=length;
this.width=width;
System.out.println("Rectangle constructor called");
}
public double area() {
return length*width;
}
public String toString() {
return "Rectangle constructor called";
}
public String getColor() {
return color;
}
}
public class Test001 {
public static void main(String[] args) {
Shape s1=new Circle("Green",3.1);
Shape s2=new Rectangle("Blue",3,4);
System.out.println("Circle color is "+s1.getColor()+" and area is "+s1.area());
System.out.println("Rectangle color is "+s2.getColor()+" and area is "+s2.area());
}
}