Instance Variables

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]

BankAccount.java
   private int balance;        // current balance in cents

*The next logical step are the private instance variables of a class.
 
*Some guidelines:

*Include only variables that describe an instance of that class. Leave out temporary variables as these can be better put into the methods of a class.
 
*Meaningful names should be selected that provide a reader with an initial idea of its semantics.
 
*Add a comment that specifies the variable in more detail: How is a value encoded (in the example above we represent a balance in cents) and which role does it play?
 
*Specify the relationships between the instance variables of a class, if there are some.
 

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]
Copyright © 2001, 2002 Andreas Borchert, converted to HTML on February 11, 2002