Here, by creating 4 classes, we can demonstrate hybrid inheritance. The inheritance of the hybrid is the combination of two types of inheritance. We are going to combine multilevel and hierarchical inheritance here.Program :
The source code is provided below to show the hybrid inheritance. The program given is compiled and successfully executed.
'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
We created a Module1 module in the program above. Here, four classes have been created: Sample1, Sample2, Sample3, and Sample4. Here, to implement hybrid inheritance, we combined multi-level and hierarchical inheritance.
Finally, we created the Main() function, which is the program entry point, where we created the Sample2 and Sample4 quality characteristics. We then called the fun1(), fun2(), fun3() and fun4() methods with the objects method.