0
namespace ShapesDemo
{
abstract class GeometricFigure
{
private int width, height;
public GeometricFigure(int width, int height)
{
this.width = width;
this.height = height;
}
public int Width
{
get { return width; }
set
{
width = value;
ComputeArea();
}
}
public int Height
{
get { return height; }
set
{
height = value;
ComputeArea();
}
}
public abstract int ComputeArea();
}
}
class Rectangle : GeometricFigure
{
private int area;
public Rectangle(int width, int height) : base (width, height)
{
}
public override int ComputeArea()
{
area = Width * Height;
return area;
}
}
class Square : Rectangle
{
public Square(int width, int height) : base(width, width)
{
}
public Square(int side) : base (width,height)
{
}
// Here is the problem. There is a requirement to add a
// second constructor that uses one dimension for both width and height,
// but I am getting an error on any attempt I use.
// Any help would be appreciated. Thank you
}
}
你爲什麼要允許'公共廣場(int width,int height)'?這與Square的含義完全相反。 – SLaks
**錯誤說**是什麼? – SLaks
你可能是指'公共廣場(int side):base(side,side)'。 –