VB.NET支持继承,而VB6.0则不支持。继承的好处在于你能使用任何人编写的类,从这些类派生自己的类,然后在自己的类中调用父类功能。在下面的例子中,Class B派生自Class A,我们将从Class B中调用Class A的方法MethodA。
Imports System
Imports System.Console
Module Module1
Sub ()
Dim bObj As B = New B
WriteLine(bObj.MethodA())
End Sub
End Module
' Class A defined
Public Class A
Function MethodA() As String
Return "Method A is called."
End Function
End Class
'Class B, inherited from Class A. All members (Public and Protected)
' can be access via B now.
Public Class B
Inherits A
Function MethodB() As String
Return "Method B is called."
End Function
End Class
可以从一个class中派生多个自定义class,也可以从多个class派生一个自定义class。