public class Increment
1: // Fig. 8.15: Increment.java
2: // final instance variable in a class.
3:
4: public class Increment
5: {
6: private int total = 0; // total of all increments
7: private final int INCREMENT; // constant variable (uninitialized)
8:
9: // constructor initializes final instance variable INCREMENT
10: public Increment( int incrementValue )
11: {
12: INCREMENT = incrementValue; // initialize constant variable (once)
13: } // end Increment constructor
14:
15: // add INCREMENT to total
16: public void addIncrementToTotal()
17: {
18: total += INCREMENT;
19: } // end method addIncrementToTotal
20:
21: // return String representation of an Increment object's data
22: public String toString()
23: {
24: return String.format( "total = %d", total );
25: } // end method toIncrementString
26: } // end class Increment
27:
28:
29: /**************************************************************************
30: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
31: * Pearson Education, Inc. All Rights Reserved. *
32: * *
33: * DISCLAIMER: The authors and publisher of this book have used their *
34: * best efforts in preparing the book. These efforts include the *
35: * development, research, and testing of the theories and programs *
36: * to determine their effectiveness. The authors and publisher make *
37: * no warranty of any kind, expressed or implied, with regard to these *
38: * programs or to the documentation contained in these books. The authors *
39: * and publisher shall not be liable in any event for incidental or *
40: * consequential damages in connection with, or arising out of, the *
41: * furnishing, performance, or use of these programs. *
42: *************************************************************************/