java P153.2 设计一个Shape接口和它的两个实现类......

it2024-12-24  7

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; } }
最新回复(0)