Interface in VB.NET
In this article You will learn How to use Interface in VB.NET.
In this article you will learn how to use Interface in VB.NET.
Interfaces:-
-
A user defined data type similar to class but contains all abstract methods.
-
All methods are abstract and public by default.
-
All such methods are overridden in child class.
-
Allows to implement the multiple inheritance.
-
A class can inherit only one other class but any number of interfaces.
-
All interfaces in .NET starts with I.
-
implements keyword to implement the interface.
-
use the Interface keyword to create an interface.
The following code demonstrates the use of interface.
Module Module1
Interface Common
Sub Leaves()
End Interface
Interface IHr
Inherits Common
Sub ShowSalary()
End Interface
Interface IFinance
Inherits Common
Sub Budget()
End Interface
Class ERP
Implements IHr
Implements IFinance
Public Sub ShowSalary() Implements IHr.ShowSalary
System.Console.WriteLine("Salary will be on 10th")
End Sub
Public Sub Budget() Implements IFinance.Budget
System.Console.WriteLine("Budget is 10 L")
End Sub
Public Sub Leaves() Implements Common.Leaves
System.Console.WriteLine("Leaves are 10 Cs, 20 EL")
End Sub
End Class
Class ITC
Public Shared Sub Main()
Dim h As IHr = New ERP()
h.ShowSalary()
h.Leaves()
End Sub
End Class
End Module
OUTPUT: