×

VB.Net Programs

VB.Net program to demonstrate the hybrid inheritance

By Nidhi Last Updated : November 11, 2024

Hybrid Inheritance in VB.Net

Here, we will demonstrate the hybrid inheritance by creating 4 classes. The hybrid inheritance is the combination of any two types of inheritance. Here we will combine multilevel and hierarchical inheritance.

Program/Source Code:

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

VB.Net code to implement the hybrid inheritance

'VB.net program to demonstrate the hybrid 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

    Class Sample4
        Inherits Sample3
        Sub Fun4()
            Console.WriteLine("Sample4.Fun4() called")
        End Sub
    End Class

    Sub Main()
        Dim S2 As New Sample2()
        Dim S4 As New Sample4()

        S2.Fun1()
        S2.Fun2()

        S4.Fun1()
        S4.Fun3()
        S4.Fun4()
    End Sub
    
End Module

Output:

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

Explanation:

In the above program, we created a module Module1. Here, we created four classes Sample1, Sample2, Sample3, and Sample4. Here, we combined the multi-level and hierarchical inheritance to implement hybrid inheritance.

At last, we created a Main() function, which is the entry point for the program, here we created the object of Sample2 and Sample4 class. After that we called method fun1(), fun2(), fun3() and fun4() methods with the objects.

VB.Net Basic Programs »


Comments and Discussions!

Load comments ↻





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