×

VB.Net Programs

VB.Net program to demonstrate the simple interface

By Nidhi Last Updated : November 13, 2024

Implementing Simple Interface in VB.Net

Here, we will create an interface with method declaration and then implement the interface in the class using the implements keyword.

Program/Source Code:

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

VB.Net code to implement the simple interface

'VB.net program to demonstrate the simple interface.

Module Module1
    Interface ISample
        Sub Fun()
    End Interface

    Class Sample
        Implements ISample
        Sub Fun() Implements ISample.Fun
            ' Method Implementation
            Console.WriteLine("Fun() called")
        End Sub
    End Class

    Sub Main()
        Dim S As New Sample()
        S.Fun()
    End Sub
End Module

Output:

Fun() called
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1. Here, we created an interface ISample that contains a declaration of the Fun() method. Then we implement the Fun() method 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 class and called the fun() method 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.