// 图形类Shape
package d922B;

public class Shape {
double getArea(ShapePara x){
return x.getArea();
}
double getArea(Rect y)
{
return y.getA()*y.getB();
}

}
//矩形类
package d922B;

public class Rect extends Shape {
private double a, b;
public Rect(double a, double b) {
super();
this.a = a;
this.b = b;
}

public double getA() {
	return a;
}

public double getB() {
	return b;
}

public void setA(double a) {
	this.a = a;
}

public void setB(double b) {
	this.b = b;
}

}

//主类
package d922B;

public class Test {

public static void main(String[] args) {
	Shape a=new Shape();
	System.out.println(a.getArea(new Circle(1)));
	System.out.println(a.getArea(new Rect(15,20)));

}

}

//运行结果

3.0
300.0

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案