All academies
All challenges

A Counter with Private State

easyclasses50 XP

Problem

Create a Counter class with a private count field starting at 0, an increment() method, and a value getter that returns the current count. The count must not be readable or writable directly from outside the class — only through the getter.

Expected output

2
3

Hints

Stuck? Reveal hints one at a time.

Solution

Try solving it yourself first — revealing is always available.

Press Run in the editor — your console output is checked automatically.
No errors
Loading...

Console output appears here. Press Run or just type — the code compiles automatically.