Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training,
learning paths, books, tutorials, and more.

Creating a Property in the CritterPropProgram

The public instance variable already created for name was easy to make, but it has some serious weaknesses. Generally, you want to write your programs to prevent problems. By making the name public, you have no way to ensure that it will get an appropriate value. Figure 4.11 shows the next version of the Critter program, Critter Prop, featuring a characteristic called the property.