private var name : Type;
access modifier: can
be public,
private or omitted
variable
name
variable
type
Figure 5-3
The access modifier considerations made so far for instance functions can be applied here as well.
On the contrary to what happens for local variables and for static variables, it is not possible to set the
value of an instance variable at the time of the declaration; the value can only be set inside a function call.
Instance variables can be referenced inside functions simply by using their variable name or their
variable name prefixed with the this term. The this identifier is mandatory inside a function that
makes use of conflicting names.
Identifiers Sequence
When naming variables and functions, it is important to be aware of how their identifiers are resolved. For
variables or functions assigned to variables, the sequence in order of priority from highest to lowest, is:
Local variables
Instance variables
Static variables
enum constructors declared in the scope
??‘
??‘
??‘
??‘
108
Part I: The Core Language
Sequence for functions is the following:
Functions stored in local variables
Instance functions
Static functions
If you have more than one local variable or function with the same name, the last declared before use
will be adopted.
Pages:
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236