In: Computer Science
Java- Write a class called Rectangle that inherits from Shape. Write a constructor that has length, width and colour as arguments. Define enough functions to make the class not abstract
abstract class Shape{
private String color;
public Shape(String c) {
color=c;
}
public abstract double area();
public abstract double perimeter();
}
class Rectangle extends Shape{
private int height;
private int width;
public Rectangle(String color,int aHeight, int aWidth) {
super(color);
height = aHeight;
width = aWidth;
}
@Override
public double area() {
return height * width;
}
@Override
public double perimeter() {
return 2 * ( height + width);
}
}
public class TestShape {
public static void main(String[] args) {
Shape s = new Rectangle("Red", 12, 10);
System.out.println(s.area());
System.out.println(s.perimeter());
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME