public abstract class Shape {
public abstract double getArea();
public abstract double getLength();
}
public class Circle extends Shape {
private double dRadius;
public Circle(double r) {
this.dRadius = r;
}
@Override
public double getArea() {
return dRadius * Math.PI * Math.PI;
}
@Override
public double getLength() {
return 2 * dRadius * Math.PI;
}
public void printString() {
System.out.println("我是圆形!我的半径是:" + this.dRadius);
}
public void printArea() {
System.out.println("圆的面积:" + getArea());
}
public void printLength() {
System.out.println("圆的周长:" + getLength());
}
}
public class Shiti1 {
public static void main(String[] args) {
Circle circle = new Circle(2d);
circle.printString();
circle.printArea();
circle.printLength();
}
}