Interface Implementation Examples
The document is archived and information here might be outdated

Interface Implementation Examples

Classes that implement an interface must implement all its properties, methods, and events.

The following example defines two interfaces. The second interface, Interface2, inherits Interface1 and defines an additional property and method.

Interface Interface1
    Sub sub1(ByVal i As Integer)
End Interface

Interface Interface2
    Inherits Interface1 ' Demonstrates interface inheritance.
    Sub M1(ByVal y As Integer)
    ReadOnly Property Num() As Integer
End Interface

The next example implements Interface1, the interface defined in the previous example:

Public Class ImplementationClass1
   Implements Interface1
   Sub Sub1(ByVal i As Integer) Implements Interface1.Sub1
      ' Place code here to implement this method.
    End Sub
End Class

The final example implements Interface2, including a method inherited from Interface1:

Public Class ImplementationClass2
   Implements Interface2
   Dim INum As Integer = 0
   Sub sub1(ByVal i As Integer) Implements Interface2.Sub1
      ' Place code here that implements this method.
   End Sub
   Sub M1(ByVal x As Integer) Implements Interface2.M1
      ' Place code here to implement this method.
   End Sub
   
   ReadOnly Property Num() As Integer Implements _
      Interface2.Num
      Get
        Num = INum
      End Get
   End Property
End Class

See Also

Interfaces Overview | Interface Statement | Interface Definition | Implements Keyword | When To Use Interfaces | Creating and Implementing an Interface | Walkthrough: Creating and Implementing Interfaces | Inheritance | Implements Statement | Inherits Statement

Show:
© 2016 Microsoft