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

VB.Net program to demonstrate the nested interface

Write a VB.Net Program for nested interface

Here, inside the class, we will create a nested interface and implement the interface methods.

Program :

The source code is provided below to demonstrate the nested interface. The program given is compiled and successfully executed.

'VB.net program to demonstrate the nested interface.

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

We created a Module1 module in the program above. Here, within the Sample class, we introduced the nested interface methods. Module1 includes an ISample1 interface that contains a nested ISample2 interface. Both interfaces provide process declarations.

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