An interviewer asked me that
How can you implement a class Foo, where you will be able to count instances of that class. There are more thread
I suppose you could also create a new SoftReference to the newly created instance in the constructor, and collect those in a static list.
If you want the instance count, you can count the references that are still alive.
This way, the reference count gets reduced when the garbage collector has done its work.