We have already seen variable fields in several code examples of previous sections. Variable fields hold values, a characteristic which they share with most (but not all) properties:
class Main { static var example:String = "bar"; public static function main() { trace(example); example = "foo"; trace(example); } }
We can learn from this that a variable
example
),String
),"bar"
) andstatic
)The example first prints the initialization value of example
, then sets it to "foo"
before printing its new value. The effect of access modifiers is shared by all three class field kinds and explained in a separate section.
It should be noted that the explicit type is not required if there is an initialization value. The compiler will infer it in this case.
Figure: Initialization values of a variable field.