Skip to main content

Practice ยท 1 of 2

A class that counts instances

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().

Difficulty: beginner

Back to lesson: Practice: Practice: Objects at Work