Solution

ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2019/imperative-programming/7/b/i/solution

The constructor stores a reference, not a copy:
val d = new Dimension(3, 4)
val f = new Frame(d)
d.width = 10
Now f.area is still , but the product of its stored dimension fields is . Even without retaining d, a client can break the same invariant through f.dimension.height = 9, because the accessor exposes the same mutable object. This is representation exposure through reference aliasing. A val prevents reassigning the reference; it does not freeze the referenced object.

New to topics? Read the docs here!