Static methods do not have an implicit
This instance argument passed to them. This allows them to be used like normal non-member procedures (for example with callback procedure pointers), the only difference being that they are encapsulated in the
typename namespace and have access to
typename's
Private or
Protected members.
Static methods can be called directly anywhere in code, like normal non-member procedures, or on objects of type
typename, similar to non-static methods, however either way there is no implicit or explicit
This (or explicit
Base) access possible from within a static method.
For member procedures with
Static in their prototype,
Static can also be specified on the corresponding procedure bodies, for improved code readability.
Static member variables are created and initialized only once independently of any object construction, in contrast to non-static member variables which are created again and again for each separate object. They always are
Shared, even if
Shared was not specified in the declaration. Thus,
Static member variables are similar to global variables, except that they are declared in a Type namespace.
Each
Static member variable declared in a Type must be explicitly allocated somewhere outside the type by using a
Dim statement. The declaration inside the Type is the prototype that is visible to every module seeing the Type declaration. The definition outside the Type allocates and optionally initializes the
Static member variable. There can only be one definition per
Static member variable: it can only be allocated in a single module, not in multiple ones. This is the same as for
Extern variables.
A
Static member variable is subject to member access control except for its definition outside the Type. If a private
Static member variable is to be explicitly initialized outside the Type's member procedures, an initializer must be provided with the definition.