Question: abstract class Shape { protected String color; protected boolean filled; public Shape ( String color, boolean filled ) { this.color = color; this.filled = filled;

abstract class Shape {
protected String color;
protected boolean filled;
public Shape(String color, boolean filled){
this.color = color;
this.filled = filled;
}
abstract double getArea();
abstract double getPerimeter();
public String toString(){
return "Shape[color="+ color +", filled="+ filled +"]";
}
}
class Circle extends Shape {
private double radius;
public Circle(String color, boolean filled, double radius){
super(color, filled);
this.radius = radius;
}
@Override
double getArea(){
return Math.PI * radius * radius;
}
@Override
double getPerimeter(){
return 2* Math.PI * radius;
}
}
class Rectangle extends Shape {
private double width;
private double length;
public Rectangle(String color, boolean filled, double width, double length){
super(color, filled);
this.width = width;
this.length = length;
}
@Override
double getArea(){
return width * length;
}
@Override
double getPerimeter(){
return 2*(width + length);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!