You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
596 B

// 圆形类,继承抽象类Shape
public class Circle extends Shape {
// 半径
private double radius;
// 构造方法:初始化半径
public Circle(double radius) {
this.radius = radius;
}
// 重写getArea方法:圆的面积 = π * r²
@Override
public double getArea() {
return Math.PI * radius * radius;
}
// 可选:getter/setter方法(方便后续扩展)
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
}