Skip to main content

Practice · 3 of 5

Trace object state across calls (E3)

CHALLENGE
Difficulty: advanced+25 XP

Trace this class and call sequence **on paper**: ``java public class Meter { private int units; private int cap; public Meter(int c) { cap = c; units = 0; } public void tick() { if (units < cap) { units++; } else { units = units / 2; } } public int get() { return units; } } ` Calls: new Meter(3), then tick(); tick(); tick(); tick(); tick();. Return the **final** value of get()`.

Back to lesson: Practice: Trace drills: state tables and misdirection