JAVA题,要求不要太复杂,我刚学,现在作业不会写,急急急

2025-01-02 23:11:25
推荐回答(1个)
回答1:

按照题目要求编写的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));

 }

}