Interface in VB.NET

In this article You will learn How to use Interface in VB.NET.
  • 1642

In this article you will learn how to use Interface in VB.NET.

Interfaces:-

  1. A user defined data type similar to class but contains all abstract methods.

  2. All methods are abstract and public by default.

  3. All such methods are overridden in child class.

  4. Allows to implement the multiple inheritance.

  5. A class can inherit only one other class but any number of interfaces.

  6. All interfaces in .NET starts with I.

  7. implements keyword to implement the interface.

  8. 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:


 

out.gif

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.