Initialising Fields

A Field may be assigned an initial value. This can be specified by an arbitrary expression that is executed when the Class is fixed by the Editor or by ⎕FIX.

:Class DomesticParrot: Parrot
    :Field Public Name
        :Field Public Talks1

     egg nm
      :Access Public
      :Implements Constructor
      Namenm
    
    ...
:EndClass ⍝ DomesticParrot

Field Talks will be initialised to 1 in every instance of the Class.

      pet⎕NEW DomesticParrot 'Dicky'

      pet.Talks
1
      pet.Name
Dicky

Note that if a Field is ReadOnly, this is the only way that it may be assigned a value.

See also: Shared Fields.