Overriding in VB.NET

This article shows OVERRIDING in VB.NET.
  • 11559

This article shows the OVERRIDING in VB.NET.

OVERRIDING: Overrides is used by derived classes (classes that inherit from a base class) to replace the original method from the base class with one of its own, which must match the same method signature.

For overriding, the methods must be OVERRIDABLE

VB Code:


Module module1

    Class A

        Public Overridable Sub Show()

            Console.WriteLine("Calling from A")

        End Sub

    End Class



    Class B

        Inherits A

        Public Overrides Sub Show()

            Console.WriteLine("Calling from B")

        End Sub

    End Class


    Class C

        Inherits B

        Public overloads Sub Show()

            Console.WriteLine("Calling from C")

        End Sub


    End Class


    Class Test

        Public Shared Sub Main()

            Dim x As A

            x = New A()


            x = New B()


            x = New C()


        End Sub

    End Class

End Module




The output shows the result of the above VB.NET code.



More Articles

© 2020 DotNetHeaven. All rights reserved.