java多边形继承
来源:百度知道 编辑:UC知道 时间:2024/05/05 14:03:19
能不能具体点
class Rectangle extends Parallelogram {
private double length;
private double width;
// constructor
public Rectangle(double length, double width) {
super(length, width);
this.length = length;
this.width = width;
}
// get the area of the rectangle
public double getArea() {
return length * width;
}
}
class Square extends Rectangle {
private double side;
// constructor
public Square(double side) {
super(side, side);
this.side = side;
}
// get the area of the square
public double getArea() {
return side * side;
}
}
再详细的就没必要了,毕竟只是为了说明多边形之间的继承关系。
public interface A{ //定义平面图形接口
public abstract double area();
}
class B imprments A{ //定义平行四边形类实现四边形接口
pr