要扩展或修改继承的方法、属性、索引器或事件的抽象实现或虚实现,必须使用 override 修饰符。

在此例中,类 Square 必须提供 Area 的重写实现,因为 Area 是从抽象的 ShapesClass 继承而来的。

 CopyCode image复制代码
abstract class ShapesClass
{
    abstract public int Area();
}

class Square : ShapesClass
{
    int x, y;
    // Because ShapesClass.Area is abstract, failing to override
    // the Area method would result in a compilation error.
    public override int Area()
    {
        return x * y;
    }
}

有关 override 关键字用法的更多信息,请参见使用 Override 和 New 关键字进行版本控制以及了解何时使用 Override 和 New 关键字

Expand 图像备注

Expand 图像示例

Expand 图像C# 语言规范

Expand image请参见