Home >>VB.Net Built-in Functions >VB.Net program to demonstrate the interface inheritance

VB.Net program to demonstrate the interface inheritance

Write a VB.Net program to demonstrate the interface inheritance

We'll build the ISample1 interface here, and then inherit the ISample1 interface from the ISample2 interface. After that, within the Sample class, we can implement the interface ISample2.

Program :

The source code to display the inheritance of the interface is given below. The program given is compiled and successfully executed.

'VB.net program to demonstrate the interface inheritance.


Module Module1
    Interface ISample1
        Sub Fun1()
    End Interface
    Interface ISample2
        Inherits ISample1
        Sub Fun2()
    End Interface
    Class Sample
        Implements ISample2
        Sub Fun1() Implements ISample2.Fun1
            Console.WriteLine("Fun1() called")
        End Sub
        Sub Fun2() Implements ISample2.Fun2
            Console.WriteLine("Fun2() called")
        End Sub
    End Class
    Sub Main()
        Dim S As New Sample()
        S.Fun1()
        S.Fun2()
    End Sub
End Module
	
Output:
Fun1() called
Fun2() called
Explanation:

We created a Module1 module in the program above. Here, we've inherited the ISample1 interface from another ISample2 interface. Inside the Sample class, we then implemented the ISample2 interface.

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


No Sidebar ads