Home Segments Top Top Previous Next

154: Mainline

You need not use a class name and field-selection operator to access a class variable in methods defined in the same class, except in places in which there is a parameter or local variable that happens to have the same name as the variable. Such parameters or local variables are said to shadow, or to override, the corresponding class variables.

You can change the value of a class variable in all the methods defined in the same class, without using the class's name, except in places in which there is a parameter or local variable that happens to have the same name. If there is such a parameter or local variable, you can still change a class variable's value by using the class's name in the assignment statement. For example, if you want to change the value of the class variable that serves as a weight for script ratings, you can write the following assignment statement:

  *-- Class name 
  |  *-- Field-selection operator 
  |  |  *-- Variable name 
  |  |  |       *-- New value 
  v  v  v       | 
----- --------  v 
Movie.wScript = 7; 

The change affects all subsequent evaluations of the class variable.