Immutable (1.3)

The section on "Immutable" in chapt. 4, page 67, of the 1st edition of the textbook sketches how one could use a mutable object as if it were immutable. The 2nd edition extends this idea with a new pattern, the Read-Only Interface.

Consider the class Position.java (in the textbook's CD). First, update the code of this class so that positions become mutable, e.g., add setter methods for x and y. Then, adopting the technique discussed in the textbook, code a test program that declares two "positions", one mutable and one immutable. Within the test program, code instructions that (attempt to) change both the mutable and the immutable positions. Verify that the compiler reports an error for the latter.