Roshawn,
As Tom suggests you can shadows a base method that was not marked
overridable.
HOWEVER!! Avoid creating a design that requires the use of shadows, as are
"anti-polymorphic", while Overrides are polymorphic.
Public Class ExampleB
Inherits ExampleA
Shadows Sub DoSomething()
Dim str as String = "Already doing something"
End Sub
End Class
For example:
Dim a As ExampleA = New ExampleA
a.DoSomething()
' Now create an ExampleA variable containing a derived object
Dim b As ExampleA = New ExampleB
b.DoSomething()
Notice that str is still "Do something already" as DoSomething is not
polymorphic, b is defined as an ExampleA type, so you get ExampleA behavior.
Overridable indicates you want polymorphism.
To continue your second example, Two can override a method such that derived
classes can no longer override them.
Public Class Two
Inherits One
Overrides NotOverridable Sub DoSomething()
Dim str as String = "Already doing something"
End Sub
End Class
This is useful when Two needs to dictate what the expected behavior will be,
without allowing derived classes to modify it.
--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -
http://www.tsbradley.net
"Roshawn" <ra*********@yahoo.comwrote in message
news:O$**************@TK2MSFTNGP04.phx.gbl...
Hi,
Is it possible to override a property, function, or sub in a base class if
the Overridable keyword isn't specified?
For example:
Public Class ExampleA
Sub DoSomething()
Dim str as String = "Do something already"
End Sub
End Class
Public Class ExampleB
Inherits ExampleA
Overrides Sub DoSomething()
Dim str as String = "Already doing something"
End Sub
End Class
Would this work?
Thanks,
Roshawn