VB.NET: Declaring a function inside a base class non-overridable
I have a base class foo
that will be use开发者_C百科d in multiple child classes of similar but slightly different function:
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
How do I get the compiler to generate an error when bar2()
is overridden by a child class?
Specify the NotOverridable keyword in the function definition:
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
NotOverridable ?
精彩评论