NotOverridable Keyword

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sonia.sardana
    New Member
    • Jul 2006
    • 95

    #1

    NotOverridable Keyword

    First of all I want to ask dat,is it a valid keyword. I have read it from MSDN help.

    NotOverridable means that if we declare a method in base class with keyword NotOverridable , we cannot override that nethod in derived class.
    But when I m declaring a method in base class as NotOverridable , I m getting the error, Check the code below--


    Public Class base
    Public NotOverridable Sub test()
    Console.WriteLi ne("soia")
    End Sub
    End Class
    Sub main()
    Dim obj As New base
    obj.test()
    Console.ReadLin e()
    End Sub

    ERROr-
    'NotOverridable ' cannot be specified for methods that do not override another method.
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #2
    It is saying that you can't create a method defined NotOverrideable unless that class itself Overrides another:

    For instance:
    [Code=vb]Private NotOverrideable Overrides Function ToString() As String
    Return "Hello World"
    End Function[/Code]

    Comment

    Working...