ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to demonstrate the tree or hierarchical inheritance

Here, we are going to demonstrate the tree or hierarchical inheritance in VB.Net.
Submitted by Nidhi, on December 26, 2020

Here, we will demonstrate the hierarchical inheritance by creating three classes Sample1, Sample2, Sample3. Here, Sample1 will be the parent class for Sample2, Sample3 class.

Program/Source Code:

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

'VB.net program to demonstrate the 
'Tree or Hierarchical inheritance.

Module Module1
    Class Sample1
        Sub Fun1()
            Console.WriteLine("Sample1.Fun1() called")
        End Sub
    End Class
    Class Sample2
        Inherits Sample1
        Sub Fun2()
            Console.WriteLine("Sample2.Fun2() called")
        End Sub
    End Class
    Class Sample3
        Inherits Sample1
        Sub Fun3()
            Console.WriteLine("Sample3.Fun3() called")
        End Sub
    End Class

    Sub Main()
        Dim S2 As New Sample2()
        Dim S3 As New Sample3()

        S2.Fun1()
        S2.Fun2()

        S3.Fun1()
        S3.Fun3()
    End Sub

End Module

Output:

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

Explanation:

In the above program, we created a module Module1. Here, we created three classes Sample1, Sample2, and Sample3. Here, Sample1 is the parent class of Sample2, Sample3 class. Each class contains a method.

At last, we created a Main() function, it is the entry point for the program, here we created the object of Sample2, Sample3 class, and called methods fun1() with both objects.

VB.Net Basic Programs »

ADVERTISEMENT
ADVERTISEMENT




Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.