You want to create a class property on which you can perform calculations before setting or returning a value.
You can create what are called
properties for classes using the
) method within the class’s constructor.
Getter/setter properties are accessed from object instances just like
any other properties, but they secretly invoke methods rather than
directly accessing an actual property of the same name. This allows
your properties to be
“smart”—you can perform
calculations on the fly rather than just assigning or retrieving a
To create a getter/setter property, first create
for the class. The getter method should not require any parameters
and should return a value. The setter method should take a single
parameter and not return any value. By convention, the getter and
setter methods are named
PropertyName is the
name of the property name they control (with the first letter
addProperty( ) method creates a new property
with the name you specify in the first parameter. The second and
third parameters passed to
specify the getter and setter methods. It is important that you do
not include the parentheses as part of the getter and setter method
names when you pass them to the
methodName( ) is wrong, and ...