Name

Class Statement

Syntax

[accessmodifier] [inheritability] ClassName    statements
End Class
accessmodifier

Use: Optional

Type: Keyword

The possible values of accessmodifier are Public, Private, and Friend. For more information, see Section 3.7 in Chapter 3.

inheritability

Use: Optional

Type: Keyword

One of the keywords, MustInherit or NotInheritable, must be used. MustInherit specifies that objects of this class cannot be created, but that objects of derived classes can be created. NotInheritable specifies that this class cannot be used as a base class.

ClassName

Use: Required

Type: String literal

This is the name of the class.

Description

Defines a class and delimits the statements that define that class’ variables, properties, and methods. For a detailed discussion with examples, see Chapter 3.

Rules at a Glance

  • ClassName follows standard Visual Basic variable-naming conventions.

  • Within a class code block, members are declared as Public, Private, Protected, Friend, or Protected Friend. The Dim keyword is equivalent to Private when used in class modules (but it is equivalent to Public in structures). Property declarations are automatically Public.

  • The Class...End Class construct can include the following elements:

    Private variable or procedure declarations

    These items are accessible within the class, but do not have scope outside of the class.

    Public variable or procedure declarations

    Public variables are public properties of the class; Public procedures are public methods of the class. ...

Get VB .NET Language in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.