Home >>VB.Net Built-in Functions >VB.Net program to use multiple-inheritance using the interface

VB.Net program to use multiple-inheritance using the interface

Write a VB.Net program to use multiple-inheritance using the interface

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

Program :

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

'VB.net program to demonstrate the

'multiple-inheritance using the interface.


Module Module1
    Interface ISample1
        Sub Fun1()
    End Interface
    Interface ISample2
        Sub Fun2()
    End Interface
    Interface ISample3
        Sub Fun3()
    End Interface
    Class Sample
        Implements ISample1, ISample2, ISample3
        Sub Fun1() Implements ISample1.Fun1
            Console.WriteLine("Fun1() called")
        End Sub
        Sub Fun2() Implements ISample2.Fun2
            Console.WriteLine("Fun2() called")
        End Sub
        Sub Fun3() Implements ISample3.Fun3
            Console.WriteLine("Fun3() called")
        End Sub
    End Class
    Sub Main()
        Dim S As New Sample()
        S.Fun1()
        S.Fun2()
        S.Fun3()
    End Sub
End Module
	
Output:
Fun1() called
Fun2() called
Fun3() called
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 entry point, here we created the Sample class object and called the methods Fun1(), Fun2(), and Fun3() that will print a suitable message on the console screen.


No Sidebar ads