JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Immediate Solutions: Creating Classes

So how do you actually create a class? You use the Class statement:

[ <attrlist> ] [ Public | Private | Protected | Friend | Protected Friend ]
[ Shadows ] [ MustInherit | NotInheritable ] Class name
 [ Implements interfacename ]
    [ statements ]
End Class

Here are the various parts of this statement:

  • attrlist—Optional. This is the list of attributes for this class. Separate multiple attributes by commas.

  • Public—Optional. Classes declared Public have public access; there are no restrictions on the use of public classes.

  • Private—Optional. Classes declared Private have private access, which is accessible only within its declaration context.

  • Protected—Optional. Classes declared Protected have protected access, which means they are accessible only from within their own class or from a derived class.

  • Friend—Optional. Classes declared Friend have friend access, which means they are accessible only within the program that contains their declaration.

  • Protected Friend—Optional. Classes declared Protected Friend have both protected and friend accessibility.

  • Shadows—Optional. Indicates that this class shadows a programming element in a base class.

  • MustInherit—Optional. Indicates that the class contains methods that must be implemented by a deriving class.

  • NotInheritable—Optional. Indicates that the class is a class from which no further inheritance is allowed.

  • name—Required. Name of the class.

  • interfacename—Optional. The name of the interface implemented by this class.

  • statements—Optional. The statements that make up the variables, properties, events, and methods of the class.

Each attribute in the attrlist part has the following syntax:

<attrname [({ attrargs | attrinit })]> Attrlist

Here are the parts of the attrlist part:

  • attrname—Required. Name of the attribute.

  • attrargs—Optional. List of arguments for this attribute. Separate multiple arguments by commas.

  • attrinit—Optional. List of field or property initializers. Separate multiple initializers by commas.

You place the members of the class inside the class itself. You also can nest class declarations. We've already seen a number of examples; here's how we set up a class named DataClass:

Public Class DataClass
    Private value As Integer

    Public Sub New(ByVal newValue As Integer)
        value = newValue
    End Sub

    Public Function GetData() As Integer
        Return value
    End Function
End Class
Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor