A class packages data and related behavior. For example, a WorkOrder class might store data describing a customer’s work order in its properties. It could contain methods (subroutines and functions) for manipulating the work order. It might provide methods for scheduling the work, modifying the order’s requirements, and setting the order’s priority.

Here is the syntax for declaring a class:

[attribute_list] [Partial] [accessibility] [Shadows] [inheritance] _
Class name[(Of type_list)]
    [Inherits parent_class]
    [Implements interface]
End Class

The only things that all class declarations must include are the Class clause (including the class’s name) and the End Class statement. Everything else is optional. The following code describes a valid (albeit not very interesting) class:

Class EmptyClass
End Class

The following sections describe the pieces of the general declaration in detail.


The optional attribute_list is a comma-separated list of attributes that apply to the class. An attribute further refines the definition of a class to give more information to the compiler and the runtime system.

Instead of using commas to separate multiple attributes inside one set of brackets, you can place each attribute inside its own brackets. For example, the following code defines two classes, each having two attributes: Serializable and Obsolete.
<Serializable(), Obsolete("No longer supported. Use Sku instead")> Public Class SkuNumber ... ...

Get Visual Basic 2012 Programmer's Reference now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.