ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to demonstrate the hybrid inheritance

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

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 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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

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.