This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
If you want to know how many instances of the class you defined are created, you can accomplish it by adding a static field to your class definition and increment it each time an instance is created.
Though, I can't really see a good point of doing it...
The quieter you are, the more you are able to hear.
Joined: Aug 24, 2012
How increase that static value every time of creating objest..
leela krishhna wrote:How increase that static value every time of creating objest..
Ple\ase give the code for it...
I suppose you've already heard of static variables, and know how to use them. If not, I would suggest you go and read about it a little, so you might get an idea what I was talking about.
Anyway, key words are - every time you CREATE an object. Any idea now?
That might get you the number of instances created, but you do not know whether any have gone out of scope or been garbage collected.
It will also get you 0 out of 10 for good object‑oriented design. That count variable might be modified outside your Demo class, and you would never know about it.