按照题目要求编写的Java程序如下
interface Shape{
public double area(double a);
}
class Square implements Shape{
public double area(double a){
return a*a;
}
}
class Circle implements Shape{
public double area(double a){
return Math.PI*a*a;
}
}
public class Test{
public static void main(String[] args){
Square s=new Square ();
System.out.println("正方形的面积为"+s.area(2));
Circle c=new Circle();
System.out.println("圆的面积为"+c.area(3));
}
}