Declaring Instances

[This is preliminary documentation and subject to change.]

An instance is an object that is derived from a WBEM class. To declare the most basic instance of a class, use the Instance of keyword followed by the class name, curly braces, and a semi-colon:

instance of ClassName
{

};

All properties of the class are properties of each instance derived from the class. If the class is a derived class, instances inherit all of the properties belonging to both the derived class and its base class.

Because properties are strongly typed, instances can not change the type of properties that they have inherited. The value of these properties, however, can be changed. By default, when a class assigns a default value to a property, that value is inherited along with the property. Instances can override that value by placing an assignment statement between the curly braces as follows:

instance of ClassName
{
    InheritedProp = "value";
};

Instances need not provide explicit values for properties unless the property is a key. Values for key properties must be explicitly set to enable the instance to be properly identified. System properties cannot be set in the instance declaration; they are assigned values by the CIM Object Manager when the instance is created.

Instances can also inherit optional tags known as qualifiers that are attached to the class or properties of the class. When the flag ToInstance is associated with a qualifier that is attached to a class, that qualifier is propagated to all of the instances of that class. ToInstance is one of several qualifier flags known as flavors. Flavors provide information about the use of the qualifier to which they are associated. For more information about qualifiers and qualifier flavors, see Using Qualifiers and Using Qualifier Flavors.

The following class and instance declarations show how an instance specifies data for properties defined by the class. The class defines three properties: a character string, a 32-bit signed integer, and a 32-bit unsigned integer. The instance provides data values for each of these properties.

class MyClass 
{
    string   strProp;
    sint32   dwProp1;
    uint32       dwProp2;
}

instance of MyClass 
{
    strProp = "hello";
    dwProp1 = -1;
    dwProp2 = 0xffffffff;
}