[previous] [up] [next]     [index]
Next: Initial Values Up: Creating Classes Previous: Initialization Variables

Instance Variables

Each instance-variable-clause declares a number of instance variables for instances of the class, or expressions to be evaluated when an instance of the class is created. The first part of a clause is the clause specifier, one of sequence, public, private, etc. A clause specifier determines the properties of instance variables declared in its clause:

Each clause specifier can be used for any number of clauses in any order within a single class*/names expression.

The collection of instance variable declarations induces two sets of variables:

The same identifier can be used as an internal variable and an external variable, and it is possible to use the same identifier as internal and external variables for different bindings (as long as all internal variables are distinct and all external variables are distinct).

For public, override, and private instance variables, the instance-var-initial-value-expr expression provides a value for the variable in an object; when an initial value expression is not given, (void) is used. The process for evaluating initial value expressions is described in section 6.3.3 and section 6.4.

For each public instance variable defined in a class, the superclass (or any of its ancestors) must not contain a declaration for the variable. For each override instance variable, the superclass must already contain a declaration. These properties are verified when the class*/name expression is evaluated; if a public variable is found in the superclass or a override variable is not found, the exn:object exception is raised.

For inherit and rename instance variables, the inherited-variable or external-inherited-variable specifies a (public) instance variable from the superclass. This inheritance is verified when the class*/name expression is evaluated; if an inherited instance variable is not found in the superclass (or one of its ancestors), the exn:object exception is raised. The process that gives values to inherited variables is described in section 6.4.


[previous] [up] [next]     [index]
Next: Initial Values Up: Creating Classes Previous: Initialization Variables

PLT