CSS font stacks & developer FAQs with Web standards
Site navigation below

One of hundreds of answers available with our premium content service.

Part answer

A: To count all instances of a class you should create a static int variable to store the number of instances and include an increment statement in all constructors. You must also implement a final finalize() method that is called upon garbage collection to decrement the count. And since multiple instances may increment and decrement the static value in separate threads, these statements should be enclosed in a synchronized block, as in the example below.

… full answer hidden

Click for full answers

Premium members click below for full answer
How can I count the number of instances of an object?

Home · Web fonts · Font stacks · FAQs · Java · CSS · Javascript · HTML · Site manager