A static counter in the class's constructor should do the job. If you want to actually track the object, you may have to implement some kind of object factory and object pooling mechanism.
It is particularly not possible to do this for classes that are part of
Java language itself since they are pre-packaged classes and you cannot modify their code. However, you can wrap those classes, for example, an ArrayList inside a custom class and implement a factory
pattern if you
really want to keep track of the instances.
Cheers!
------------------
Ajith Kallambella M. Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.