提供对
Type的非静态方法的基本类型成员的显式访问
语法
Base.member
Base [ .Base ... ] .member
说明
Base提供了一种在使用
Extends从另一类型派生的用户定义类型的非静态方法的上下文中提供了一种明确访问特定基类型成员的方法。
通过重复使用
Base,如
base.base.base.member所示,可以访问任何所需的基类型,以防多种级别的继承。
当基类型的成员被本地变量或派生类型的成员使用相同的标识符遮蔽时,
Base特别有用。
Base然后允许对基类型的明确访问。
对于虚拟方法,base.method()总是调用base方法,而不是重写方法。
例子
Type Parent
As Integer a
Declare Constructor(ByVal As Integer = 0)
Declare Sub show()
End Type
Constructor Parent(ByVal a As Integer = 0)
This.a = a
End Constructor
Sub Parent.show()
Print "亲", a
End Sub
Type Child extends Parent
As Integer a
Declare Constructor(ByVal As Integer = 0)
Declare Sub show()
End Type
Constructor Child(ByVal a As Integer = 0)
'' Call base type'的构造函数
Base(a * 3)
This.a = a
End Constructor
Sub Child.show()
'' Call base type's show()方法,而不是我们的
Base.show()
'' Show both a fields, the base type's and ours'
Print "儿童", Base.a, a
End Sub
Type GrandChild extends Child
As Integer a
Declare Constructor(ByVal As Integer = 0)
Declare Sub show()
End Type
Constructor GrandChild(ByVal a As Integer = 0)
'' Call base type'的构造函数
Base(a * 2)
This.a = a
End Constructor
Sub GrandChild.show()
'' Call base type's show()方法,而不是我们的
Base.show()
'' Show both a fields, the base.base type's, the base type's and ours'
Print "孙子", Base.Base.a, Base.a, a
End Sub
Dim As GrandChild x = GrandChild(3)
x.show()
方言差异
与QB差别
参考