Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2014/imperative-programming/6/b/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2014 Imperative programming 6 b Solution by
Codex 0 2026-10-31
In Scala trait linearization, the rightmost mixed-in trait takes priority. Merge inherited linearizations while retaining a shared ancestor only at its final position; For example,
super advances to the next implementation in the resulting chain. Ignoring predefined bases, the lookup orders areLife1, Exercise, Work, Life
Life2, Dance, Exercise, Program, Study, Work, Fun, Life
Life3, Program, Study, Work, Dance, Fun, Exercise, LifeDance alone has order Dance, Fun, Exercise, Life. In Life2, the additional Program branch already contains Fun before Life; keeping that shared ancestry in its later position moves Fun after Work, while Dance still takes priority. Reversing the mixins yields the third chain above.Each The
describe first delegates and then prints, so the lines appear in the reverse of the method lookup order. The exact output, including the two blank lines, isI live.
I work.
I exercise.
I live.
I have fun.
I work.
I study.
I program.
I exercise.
I dance.
I live.
I exercise.
I have fun.
I dance.
I work.
I study.
I program.super inside a trait therefore need not call that trait's isolated textual parent; the receiving object's full Scala trait linearization controls the next body. New to topics? Read the docs here!