when you need this only for evaluating answers for the GC questions, why don't you just modify the classes with a constructor, that count++es a static int variable for creation and an override of the finalize() method that count++es a static int variable for garbage collection? Perhaps both with a system out of a line of information?