
17 Classes
17.4 Fields
17.4.5 Variable initializers
17.4.5.2 Instance field initialization
Paragraph 11 The instance field variable initializers of a class correspond to a sequence of assignments that are executed immediately upon entry to any one of the instance constructors (§17.10.2) of that class. 2 The variable initializers are executed in the textual order in which they appear in the class declaration. 3 The class instance creation and initialization process is described further in §17.10.
Paragraph 21 A variable initializer for an instance field cannot reference the instance being created. 2 Thus, it is a compile-time error to reference this in a variable initializer, as it is a compile-time error for a variable initializer to reference any instance member through a simple-name. [Example: In the example
class A
{
int x = 1;
int y = x + 1; // Error, reference to instance member of this
}
the variable initializer for y results in a compile-time error because it references a member of the instance being created. end example]
| |
| Jagger Software Ltd | |
| Company # 4070126 | |
| VAT # 762 5213 42 |