|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
Causes the current class or interface to inherit the attributes, variables, properties, procedures, and events from another class or set of interfaces.
If used, the Inherits statement must be the first non-blank, non-comment line in a class or interface definition. It should immediately follow the Class or Interface statement.
You can use Inherits only in a class or interface. This means the declaration context for an inheritance cannot be a source file, namespace, structure, module, procedure, or block.
Class Inheritance. If a class uses the Inherits statement, you can specify only one base class.
A class cannot inherit from a class nested within it.
Interface Inheritance. If an interface uses the Inherits statement, you can specify one or more base interfaces. You can inherit from two interfaces even if they each define a member with the same name. If you do so, the implementing code must use name qualification to specify which member it is implementing.
An interface cannot inherit from another interface with a more restrictive access level. For example, a Public interface cannot inherit from a Friend interface.
An interface cannot inherit from an interface nested within it.
An example of class inheritance in the .NET Framework is theclass, which inherits from the class. This provides to ArgumentException all the predefined properties and procedures required by system exceptions, such as the property and the method.
An example of interface inheritance in the .NET Framework is theinterface, which inherits from the interface. This causes ICollection to inherit the definition of the enumerator required to traverse a collection.
The following example uses the Inherits statement to show how a class named thisClass can inherit all the members of a base class named anotherClass.
Public Class thisClass Inherits anotherClass ' Add code to override, overload, or extend members ' inherited from the base class. ' Add new variable, property, procedure, and event declarations. End Class
The following example shows inheritance of multiple interfaces.
Public Interface thisInterface Inherits IComparable, IDisposable, IFormattable ' Add new property, procedure, and event definitions. End Interface
The interface named thisInterface now includes all the definitions in the, , and interfaces The inherited members provide respectively for type-specific comparison of two objects, releasing allocated resources, and expressing the value of an object as a String. A class that implements thisInterface must implement every member of every base interface.