代码之家  ›  专栏  ›  技术社区  ›  Heather M

VB.NET:声明基类中的函数不可重写

  •  0
  • Heather M  · 技术社区  · 16 年前

    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() 是否被子类重写?

    2 回复  |  直到 16 年前
        1
  •  3
  •   Andy    16 年前

    指定 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
    
        2
  •  1
  •   mwilson    16 年前
    推荐文章