A good answer might be:The two instance variables can be made private. | ||
MyPoint with better EncapsulationHere is a revised version of the program. Now MyPoint objects are immutable because even with a reference, methods can't make any changes to the object.
Since ImmutablePoint objects are immutable, a constructor is needed to initialize instance variables to their permanent values. | ||
QUESTION 13:(Thought Question:) Would it be possible to write a PointDoubler class for ImmutablePoint objects? Click Here after you have answered the question |