作业不会做,求救!
定义一个抽象类Shape,它包含两个属性X和Y和一个抽象方法Area()。不同的形状如Rentangle(矩形),circle(圆)派生自Shape类,并为每个图形计算面积。每个派生类都有各自的Area()重写实现。创建相应的实例并求出其面积。
我写了抽象类Shape,和Rentangle(矩形),圆一样的写法就不多写了!!!
abstract class Shape
{
public Shape()
{
}
public Shape(double x,double y)
{
this.x = x;
this.y = y;
}
private double x;
public double X
{
get { return x; }
set { x = value; }
}
private double y;
public double Y
{
get { return y; }
set { y = value; }
}
public abstract double Area();
}
class Rentangle:Shape
{
public Rentangle(double x, double y)
{
base.X = x;
base.Y = y;
}
public override double Area()
{
return X * Y;
}
}