Skip to main content

Practice · 1 of 2

A class that counts instances

CHALLENGE
Difficulty: beginner+25 XP

Inside Solution, write a nested static class Widget with a private final String name, a constructor that stores it, a getter, and a static int count that tracks how many Widgets have been created. Solution.Widget.of("a") style calls are not needed — the grader creates new Solution.Widget("a") directly and reads Solution.Widget.getCount().

Back to lesson: Practice: Practice: Objects at Work