Skip to main content

Practice · 4 of 5

Trace the alias

CHALLENGE
Difficulty: intermediate+25 XP

Two Bag references are created, then the sequence below runs. Implement after() to **return the final value of the first bag's field** — but by simulating the sequence in code, not hardcoding. ``java Bag a = new Bag(10); Bag b = a; // alias! b.value = b.value + 5; b = new Bag(99); b.value = b.value + 1; a = b; // now a follows b ` First trace on paper what a.value is at the end, then encode that final value in after()`.

Back to lesson: Practice: Reading specs like the exam writes them