SyntaxImplements interfaceName[, interfaceName...]
DescriptionThe Implements statement specifies that a class or structure will implement an interface defined. The Implements statement appears on the line immediately following the Class clause, or immediately after the Inherits line if the class definition includes an Inherits statement: Friend Class ClassWithAPurpose Implements IPurpose ... or: Friend Class ClassWithAPurpose Inherits ClassWithLimitedPurpose Implements IPurpose ... A single class may implement multiple interfaces. Usage at a Glance
ExampleFriend Interface IAnimal ReadOnly Property Name( ) As String Function GetFood( ) As String Function GetNoise( ) As String End Interface Friend Class Wolf Implements IAnimal Public ReadOnly Property Name( ) As String _ Implements IAnimal.Name Get Return "Wolf" End Get End Property Public Function GetFood( ) As String Implements IAnimal.GetFood Return "caribou, salmon, other fish" End Function Public Function GetNoise( ) As String Implements IAnimal.GetNoise Return "howl" End Function End Class Module GeneralCode Public Sub TestAnimal( ) Dim loneWolf As IAnimal=New Wolf MsgBox(loneWolf.GetNoise( )) loneWolf = Nothing End Sub End Module Version DifferencesIn VB 6, the Implements statement does not support events; any events publicly declared in an interface are ignored. VB under .NET allows interface events to be implemented in classes and structures. See AlsoImplements Statement, Interface...End Interface Statement |