我有以下情况:
IShape
定义方法Draw
。Circle
实施IShape
和方法Draw
。Rectangle
实施IShape
和方法Draw
。Square
扩展Rectangle
并覆盖方法Draw
。我为以上场景编写了如下代码:
class Program
{
static void Main(string[] args) { }
}
public interface IShape
{
void Draw();
}
public class Circle : IShape
{
public void Draw()
{
throw new NotImplementedException();
}
}
public class Rectangle : IShape
{
public void Draw()
{
throw new NotImplementedException();
}
}
public class Square : Rectangle
{
public virtual void Draw()
{
throw new NotImplementedException();
}
}
我无法获得class Square extends Rectangle and overrides the method Draw
的最后一个场景。
任何帮助?
答案 0 :(得分:5)
Rectangle.Draw virtual,Square.Draw override
public class Rectangle : IShape
{
public virtual void Draw()
{
throw new NotImplementedException();
}
}
public class Square : Rectangle
{
public override void Draw()
{
throw new NotImplementedException();
}
}