O'Reilly logo

Special Edition Using Java 2 Standard Edition by Geoff Friesen, Chuck Cavaness, Brian Keeton

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.

Start Free Trial

No credit card required

Variables—Defining State

Obviously, variables are an integral part of programs and, thus, classes as well. In Chapter 3, you examined the various types of variables, but now you must also consider how they are employed in your programs and the different roles they can assume.

When creating variables, whether they are as simple as integers or as complex as derived classes, you must consider how they will be used, what code will require access to the variables, and what degree of protection you want to provide to these variables.

The capability to access a given variable is dependent on two things: the access specifier used when creating the variable and the location of the variable declaration within a class.

See "Literals: Assigning Values," ...

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

Start Free Trial

No credit card required