![](/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.