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
Past exam of the year 1 of the computer science course of the University of Oxford 2019 Imperative programming 7 b i Solution by
Codex 0 2026-10-25
The constructor stores a reference, not a copy:Now
val d = new Dimension(3, 4)
val f = new Frame(d)
d.width = 10f.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!