This documentation is archived and is not being maintained.

Interface Statement

Declares the name of an interface, as well as the properties, methods and events that comprise the interface.

[ <attrlist> ] [ Public | Private | Protected | Friend | Protected Friend ] _
[ Shadows ] Interface name
   [ Inherits interfacename[, interfacename ]]
   [ [ Default ] Property proname ]
   [ Function memberame ]
   [ Sub memberame ]
   [ Event memberame ]
End Interface


Optional. List of attributes that apply to this interface. Multiple attributes are separated by commas.
Optional. Entities declared with the Public modifier have public access. There are no restrictions on the use of public entities.
Optional. Entities declared with the Private modifier have private access. A private entity is accessible only within its declaration context, including any nested entities.
Optional. Entities declared with the Protected keyword have protected access. They are accessible only from within their own class or from a derived class. Protected access can be specified only on members of classes. It is not a superset of friend access.
Optional. Entities declared with the Friend modifier have friend access. An entity with friend access is accessible only within the program that contains the entity declaration. Interfaces that do not specify an access modifier are declared as Friend by default.
Protected Friend
Optional. Entities declared with the Protected Friend modifiers have the union of protected and friend accessibility.
Optional. Indicates that this interface shadows an identically named programming element in a base class. You can shadow any kind of declared element with any other kind. A shadowed element is unavailable from within the derived class that shadows it, unless the shadowing element is inaccessible, for example if it is Private.
Required. Name of the interface; follows standard variable naming conventions.
Optional. Specifies that the interface being declared inherits the properties and methods from the interface specified by interfacename.
Required if optional Inherits statement is present. Indicates the name of one or more interfaces being inherited.
Optional. Indicates that the property with which the Default keyword is associated is the default property for the interface.
Optional. Indicates a Property procedure that is a member of the interface.
Optional. Indicates a Function procedure that is a member of the interface.
Optional. Indicates a Sub procedure that is a member of the interface.
Optional. Indicates an Event that is a member of the interface.
Required if optional Property, Event, Function, or Sub statements exist. Indicates the name of the property, procedure, or event.
End Interface
Terminates an Interface block.

Each attribute in the attrlist part has the following syntax and parts:

attrname [({ attrargs | attrinit })]

attrlist Parts

Required. Name of the attribute. Must be a valid Visual Basic identifier.
Optional. List of positional arguments for this attribute. Multiple arguments are separated by commas.
Optional. List of field or property initializers for this attribute. Multiple initializers are separated by commas.


The methods and properties of an interface are implemented in a class. When methods are implemented, the return data type and the argument data types must exactly match those of the method described in the Interface block. The method name, however, need not be the same as that described in the Interface block. Methods being implemented in a class cannot be designated as Shared, nor can they be Private, except in a non-inheritable class.

The Interface statement can appear in the declaration section of any module. Interfaces are implicitly Friend by default but can be explicitly declared Public, Friend, Protected, Protected Friend or Private.

An interface can have, at most, one default property. This implies that an interface can either inherit only one interface containing a default property, or its definition block can contain one property that is marked as default.

An interface cannot inherit from another interface whose access level is more restrictive than its own. For example, a public interface cannot inherit a friend interface.


This example uses the Interface statement to define a MyInterface interface, which must be implemented with a Property statement and a Function statement.

Public Interface MyInterface
   Property MyProp(ByVal MyStr As String)
   Function MyFunc(ByVal MyInt As Integer) As Integer
End Interface

See Also

Class Statement | Function Statement | Inherits Statement | Implements Statement | Interfaces in Visual Basic .NET | Sub Statement