如何:在 Visual Basic 中继承类

更新:2007 年 11 月

此示例定义 Circle 和 Rectangle 类(它们均继承自 Shape 类),以及 Square 类(继承自 Rectangle 类)。

示例

此代码示例也可用作 IntelliSense 代码段。在代码段选择器中,此代码示例位于“Visual Basic 语言”中。有关更多信息,请参见如何:在代码中插入代码段 (Visual Basic)

Public Class Shape
    ' Definitions of properties, methods, fields, and events.
End Class
Public Class Circle : Inherits Shape
    ' Specialized properties, methods, fields, events for Circle.
End Class
Public Class Rectangle : Inherits Shape
    ' Specialized properties, methods, fields, events for Rectangle.
End Class
Public Class Square : Inherits Rectangle
    ' Specialized properties, methods, fields, events for Square.
End Class

编译代码

此示例需要:

  • System 命名空间的引用。

    说明:

    请确保您想要继承的类未被定义为 NotInheritable。

请参见

任务

如何:绘制空心形状

参考

NotInheritable

其他资源

Visual Basic 中的继承

创建和使用对象