This chapter discusses user-defined classes and abstract data types (ADTs) in Java. It covers defining classes with private, protected, public, and static members. Constructors and finalizers are examined. The toString method is explored. Abstract data types are introduced as data types that specify logical properties without implementation details. An example candy machine problem is presented to demonstrate defining classes for a non-GUI and GUI application to model a candy machine with items for sale, a cash register, dispenser, and other components.
43. Static Members of a Class (continued) void setX( int a) { x = a; } public String toString() { return ("x = " + x + ", y = " + y + ", count = " + count); } public static void incrementY() { y++; } } Illustrate illusObject = new Illustrate(); Illustrate.incrementY(); Illustrate.count++;
44. Static Members of a Class (continued) Illustrate illusObject1 = new Illustrate(3); Illustrate illusObject2 = new Illustrate(5);
45. Static Members of a Class (continued) Illustrate.incrementY(); Illustrate.count++;