Dela via


Interface Definition

Interface definitions are enclosed within the Interface and End Interface statements. Following the Interface statement, you can add an optional Inherits statement that lists one or more inherited interfaces. The Inherits statements must precede all other statements in the declaration except comments. The remaining statements in the interface definition should be Event, Sub, Function, Property, Interface, Class, Structure, and Enum statements. Interfaces cannot contain any implementation code or statements associated with implementation code, such as End Sub or End Property.

In a namespace, interface statements are Friend by default, but they can also be explicitly declared as Public or Friend. Interfaces defined within classes, modules, interfaces, and structures are Public by default, but they can also be explicitly declared as Public, Friend, Protected, or Private.

Note

The Shadows keyword can be applied to all interface members. The Overloads keyword can be applied to Sub, Function, and Property statements declared in an interface definition. In addition, Property statements can have the Default, ReadOnly, or WriteOnly modifiers. None of the other modifiers—Public, Private, Friend, Protected, Shared, Overrides, MustOverride, or Overridable—are allowed. For more information, see Declaration Contexts and Default Access Levels.

See Also

Tasks

How to: Create and Implement Interfaces

Walkthrough: Creating and Implementing Interfaces

Concepts

Interfaces Overview

Implements Keyword and Implements Statement

Interface Implementation Examples in Visual Basic

When to Use Interfaces

Reference

Interface Statement (Visual Basic)

Inherits Statement

Overloads

Default (Visual Basic)

Other Resources

Inheritance in Visual Basic