77问答网
所有问题
用c#定义一个抽象类Shape,由它派生出两个子类:长方形rectangle和正方形类square,
用c#定义一个抽象类Shape,由它派生出两个子类:长方形rectangle和正方形类square,通过抽象方法的实现来计算两种图形的周长和面积,要求程序能够体现对象的多态性。
哪位大神知道这么弄,急啊
举报该问题
推荐答案 2015-09-20
public abstract class Shape
{
public virtual double ComputeCircumference()
{
return 0;
}
public virtual double ComputeArea()
{
return 0;
}
}
public class Rectangle : Shape
{
public double Width
{
get;
set;
}
public double Height
{
get;
set;
}
public override double ComputeCircumference()
{
return (this.Width + this.Height) * 2;
}
public virtual double ComputeArea()
{
return this.Width * this.Height;
}
}
public class Square : Shape
{
public double Width
{
get;
set;
}
public override double ComputeCircumference()
{
return this.Width * 4;
}
public virtual double ComputeArea()
{
return this.Width * this.Width;
}
}
温馨提示:答案为网友推荐,仅供参考
当前网址:
http://77.wendadaohang.com/zd/GN8WI3pYvWNG3GpNp3N.html
相似回答
大家正在搜
相关问题
定义抽象类Shape及其子类Circle(圆形)、Rect(...
如何编写程序,实现由定义抽象基类Shape(形状)派生出三个...
抽象类shape派生出类rectangle,通过过继承rec...
定义一个抽象基类Shape,它包含一个抽象方法getArea...
编写程序,定义抽象基类Shape(形状),由他派生出三个派生...
编写一个程序,声明抽象基类Shape,由它派生出3个派生类:...
C++问题问题,/*写一个程序,定义抽象基类shape,由他...
写一个程序,定义抽象基类Cshape,由它派生出5个派生类: