public static void main(String[] args) {
Square s1 = new Square();
Circle c1 = new Circle();
System.out.println("长方形面积:"+s1.area(2.0));
System.out.println("圆形面积:"+c1.area(3.0));
}
}
interface Shape{
abstract double area(double s);
}
class Square implements Shape{
public double area(double l ){
double area;
area = l*l;
return area;
}
}
class Circle implements Shape{
public double area(double r) {
double area;
area = Math.PI*r*r;
return area;
}
}
java P153.2 设计一个Shape接口和它的两个实现类......
最新推荐文章于 2023-12-02 08:37:41 发布