我有一个基类foo
,它将用于多个功能相似但略有不同的子类:
Public MustInherit Class foo
Public Function bar1() as Something
''// Perfectly OK to change what this method does
End Function
Public Function bar2() as Something
''// Does a very specific thing I don't want changed ever,
''// but this function must be inherited
End Function
End Class
当子类重写bar2()
时,如何让编译器生成错误?
答案 0 :(得分:3)
在函数定义中指定NotOverridable关键字:
Public NotOverridable Function bar2() As Something
''// Does a very specific thing I don't want changed ever,
''// but this function must be inherited
End Function
答案 1 :(得分:1)