
2个回答
展开全部
interface Shape {
public double getArea();
}
class Square implements Shape{
private double height=0;//长方形的边长
public Square(double height){
this.height=height;
}
public double getArea() {
return (height*height);
}
}
class Circle implements Shape{
private double r=0;//员的半径
private final static double PI=3.14;//圆周率
public Circle (double r){
this.r=r;
}
public double getArea() {
return PI*r*r;
}
}
public class Test{
public static void main(String[] args) {
Shape square =new Square(3);
Shape circle=new Circle(2);
System.out.println(square.getArea());
System.out.println(circle.getArea());
}
}
public double getArea();
}
class Square implements Shape{
private double height=0;//长方形的边长
public Square(double height){
this.height=height;
}
public double getArea() {
return (height*height);
}
}
class Circle implements Shape{
private double r=0;//员的半径
private final static double PI=3.14;//圆周率
public Circle (double r){
this.r=r;
}
public double getArea() {
return PI*r*r;
}
}
public class Test{
public static void main(String[] args) {
Shape square =new Square(3);
Shape circle=new Circle(2);
System.out.println(square.getArea());
System.out.println(circle.getArea());
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询