VB.Net program to demonstrate the nested interface

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

Implement nested interface in VB.Net

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

Program/Source Code:

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

VB.Net code to implement the nested interface

'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()
        S.Fun1()
        S.Fun2()
    End Sub
End Module

Output:

Fun1() called
Fun2() called
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1. Here, we implemented the methods of nested interface inside the Sample class. Module1 contains an interface ISample1 that contains a nested interface ISample2. Both interfaces contain the declaration of methods.

At last, we created a Main() function, which is the entry point for the program, here we created the object of Sample class and called the Fun1(), Fun2() 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.