Static and Instance Fields

When a field declaration includes the Shared modifier, the fields introduced by the declaration are static fields. When no Shared modifier is present, the fields introduced by the declaration are instance fields. Static fields and instance fields are two of the several kinds of variables supported by the language, and at times they are referred to as static variables and instance variables, respectively.

A static field is not part of a specific instance; instead, it identifies exactly one storage location. No matter how many instances of a class are created, there is only ever one copy of a static field for the associated application domain.

An instance field belongs to an instance. Every instance of a class contains a separate set of all the instance fields of that class.

The differences between static and instance members are described further in the Static and Instance Members section.

Example

Class SharedField
    //Static field
    Shared Public a: string;
    //Instance field
    Public b: string;
End Class;

Sub Test();
Var
    Obj: SharedField = New SharedField();
Begin
    SharedField.a := "Class";
    Obj.b := "Object";
End Sub;

See also:

Fields