Home >>VB.Net Built-in Functions >VB.Net Program to use multiple-inheritance using interface and structure

VB.Net Program to use multiple-inheritance using interface and structure

Write a VB.Net Program to use multiple-inheritance using interface and structure

Here, with method declarations, we can build three interfaces and then enforce the interfaces in the structure using the keyword implemented to achieve multiple inheritance.

Program :

Below is the source code to show the multiple-inheritance using the interface and structure. The program given is compiled and successfully executed.

'VB.net program to demonstrate the multiple-inheritance

'using interface and structure.


Module Module1
    Interface ISample1
        Sub Fun1()
    End Interface
    Interface ISample2
        Sub Fun2()
    End Interface
    Interface ISample3
        Sub Fun3()
    End Interface
    Structure Sample
        Implements ISample1, ISample2, ISample3
        Sub Fun1() Implements ISample1.Fun1
            Console.WriteLine("Fun1() called inside the structure")
        End Sub
        Sub Fun2() Implements ISample2.Fun2
            Console.WriteLine("Fun2() called inside the structure")
        End Sub
        Sub Fun3() Implements ISample3.Fun3
            Console.WriteLine("Fun3() called inside the structure")
        End Sub
    End Structure
    Sub Main()
        Dim S As New Sample()
        S.Fun1()
        S.Fun2()
        S.Fun3()
    End Sub
End Module
	
Output:
Fun1() called inside the structure
Fun2() called inside the structure
Fun3() called inside the structure
Explanation:

We created a Module1 module in the program above. We introduce multiple-inheritance here by building three ISample1, ISample2, and ISample3 interfaces that contain a method declaration. Then we used the implementation keyword to introduce the methods in the Sample class.

Finally, we created a Main() function, which is the program's entry point, here we created the Sample structure object and named the methods Fun1(), Fun2(), and Fun3() that will print a suitable message on the console screen.


No Sidebar ads