设计一个抽象类图形类,在该类中包含有至少两个抽象方法求周长和求面积,分别定义圆形类、长方形类、正方形类来继承图形类,并实现上述两个方法。并创建实例验证。
直接上代码了
package ThirdDay;
abstract class Shape {
public abstract Double calculateS();
public abstract Double calculateC();
}
class Rectangle extends Shape{
private double l;
private double s;
public Rectangle(double l, double s) {
this.l = l;
this.s = s;
}
public double getL() {
return l;
}
public void setL(double l) {
this.l = l;
}
public double getS() {
return s;
}
public void setS(double s) {
this.s = s;
}
@Override
public Double calculateS() {
return s*l;
}
@Override
public Double calculateC() {
return 2*(s+l);
}
}
class Square extends Shape{
private double sideLength;
public Square(double sideLength) {
this.sideLength = sideLength;
}
public double getSideLength() {
return sideLength;
}
public