VB.Net 2008 Working WinForms Example
The following example demonstrates implementing a very simple interface. The interface is named IHuman which includes one property and one method. Our resulting class is named CyborgHuman and, for clarity, our CyborgHuman class also inherits from a class called Cyborg.
Create a form and place a button on it and alter the code as follows:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyRobot As New CyborgHuman
MyRobot.HumanName = "Nicole"
MyRobot.Speak("Hi, my name is " & MyRobot.HumanName & ".")
'Notice you do not specify visibility in an interface.
'Visibility is determined by the implementing class.
Public Interface IHuman
Sub Speak(ByVal pSentence As String)
Public Class Cyborg
Public Class CyborgHuman
Private FHumanName As String
Public Property HumanName() Implements IHuman.HumanName
FHumanName = value
Sub Speak(ByVal pSentence As String) Implements IHuman.Speak
Default Interface Visibility: Friend
If you do not specify an interfaces visibility, the default is Friend (accessible from types in the same assembly) but an interface's members are always public -- which makes sense but is noteworthy.
Interface ITalk //Default visibility is Internal.