VB.Net program to demonstrate the multiple-inheritance using interface and structure

Here, we are going to demonstrate the multiple-inheritance using interface and structure in VB.Net.
Submitted by Nidhi, on December 27, 2020 [Last updated : March 06, 2023]

Multiple-inheritance using interface and structure in VB.Net

Here, we will create three interfaces with method declarations and then implement the interfaces in the structure using the implements keyword to achieve multiple-inheritance.

Program/Source Code:

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

VB.Net code to implement the multiple-inheritance using interface and structure

'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
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1. Here, we implement multiple-inheritance by creating three interfaces ISample1, ISample2, and ISample3 that contain a declaration of methods. Then we implemented the methods in the Sample class using the implements keyword.

At last, we created a Main() function, which is the entry point for the program, here we created the object of Sample structure and called the Fun1(), Fun2(), and Fun3() methods that will print an appropriate message on the console screen.

VB.Net Basic Programs »






Comments and Discussions!

Load comments ↻






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