Home Segments Index Top Previous Next

216: Mainline

To get the assigned value of a Vegetable instance's instance variable, you must use a method that is known to instances of the Vegetable class, again because only such methods have access to instance variables. You can, for example, define a unary message, fCalories, for instances of Vegetable:

Vegetable method definition • instance 
fCalories 
  ^ fCalories 

Because fCalories is defined for instances of Vegetable, fCalories is free to refer to—and to answer the value of—the instance variable, fCalories, in a Vegetable instance.