![](/img/trans.png)
[英]How to override a method inherited from a base class, which in turn implemented it from an interface?
[英]How to extend a class and override a method which is from interface?
我有以下情况:
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
。
有什么帮助吗?
虚拟Rectangle.Draw,Square.Draw覆盖
public class Rectangle : IShape
{
public virtual void Draw()
{
throw new NotImplementedException();
}
}
public class Square : Rectangle
{
public override void Draw()
{
throw new NotImplementedException();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.