interface Shape {
double area();
}
class Circle implements Shape {
private double radius;
Circle(double r) {
radius = r;
}
public double area() {
return Math.PI * radius * radius;
}}
class Rectangle implements Shape {
private double width, height;
Rectangle(double w, double h) {
width = w;
height = h;
}
public double area() {
return width * height;
}}
public class Test {
public static void main(String[] args) {
Shape[] shapes =
{new Circle(2), new Rectangle(3, 4)};
for (Shape s : shapes) {
System.out.printf(“Area: %.2f\n”, s.area());
}
}}
问题: 程序的输出结果是什么?(保留两位小数)
点点赞赏,手留余香
给TA打赏




评论0