VB.Net Program to Call Base Class and Derived Class Overridable Method Using Base Class Reference

You are currently viewing VB.Net Program to Call Base Class and Derived Class Overridable Method Using Base Class Reference

VB.Net program to call base class and derived class overridable method using base class reference

'VB.net program to call base class and derived class 
'overridable method using base class reference.

Module Module1
    Class Sample1
        Overridable Sub Fun()
            Console.WriteLine("Sample1.Fun() called")
        End Sub
    End Class

    Class Sample2
        Inherits Sample1
        Overrides Sub Fun()
            Console.WriteLine("Sample2.Fun() called")
        End Sub
    End Class

    Sub Main()
        Dim S As Sample1 = New Sample1()
        S.Fun()

        S = New Sample2()
        S.Fun()
    End Sub
End Module

Output

Sample1.Fun() called
Sample2.Fun() called
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply