How many objects are created for a particular class how to find?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thulaseeram
    New Member
    • Sep 2006
    • 23

    How many objects are created for a particular class how to find?

    Hi,

    How to find out, the number of objects created to a particular class.

    Thanks,
    Ram
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by thulaseeram
    Hi,

    How to find out, the number of objects created to a particular class.

    Thanks,
    Ram
    You could use a static variable to count them every time they are created in an instance initializer

    Comment

    • rameshwar8787
      New Member
      • Mar 2010
      • 1

      #3
      Count Number of Object Created for a Class

      class One
      {
      static int count = 0;
      One()
      {
      count++;
      System.out.prin tln("Number of Object created :"+count);
      }
      public static void main(String[] args)
      {
      new One();
      new One();
      new One();
      new One();
      One o = new One();
      }
      }

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        Are you talking about the number of objects of that class, or internal class members?

        Comment

        Working...