VB.Net program to demonstrate the inheritance with the protected member

Here, we are going to demonstrate the inheritance with the protected member in VB.Net.
Submitted by Nidhi, on December 26, 2020 [Last updated : March 06, 2023]

Inheritance with the protected member in VB.Net

Here, we will demonstrate the protected member in the inheritance.

Program/Source Code:

The source code to demonstrate the inheritance with the protected member is given below. The given program is compiled and executed successfully.

VB.Net code to implement the inheritance with the protected member

'VB.net program to demonstrate the inheritance 
'with the protected member.

Module Module1
    Class Sample1
        Protected Sub Fun1()
            Console.WriteLine("Sample1.Fun1() called")
        End Sub
    End Class
    Class Sample2
        Inherits Sample1
        Sub Fun2()
            Fun1()
            Console.WriteLine("Sample2.Fun2() called")
        End Sub
    End Class
   
    Sub Main()
        Dim obj As New Sample2()
        obj.Fun2()
    End Sub
End Module

Output:

Sample1.Fun1() called
Sample2.Fun2() called
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1. Here, we created two classes Sampl1, Sample2. Here, Sample1 is the parent class of Sample2. But Sample1 contains a protected method that can be accessed within the Sample2 class. But we cannot access the same method with the object of Sample2 class.

At last, we created a Main() function, it is the entry point for the program, here we created the object of Sample2 and called method fun2() with the object of Sample2 class.

VB.Net Basic Programs »






Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.