title: How to count the number of instances of a particular class in inheritance tree, created explicitly?
body: <pre><code>class A { 
      static int i;
      {
          System.out.println("A init block"+ ++i);
      }
  
  }
  class B extends A {
      static int j;
      {
          System.out.println("B init block"+ ++j);
      }
  }
  class C extends B {
      static int k;
      {
          System.out.println("C init block"+ ++k);
      }
          public static void main(String abc[])
          {
            C c =new C();
          }
  }
  </code></pre>
  
  <p>In the code above, we can easily count the number of objects created for each class.
  But if i want to check the number of object created explicitly ,  i mean if I create C's object using new C(), or B's object using new B(), then it should give the count accordingly</p>
  
  <p>Take for example,</p>
  
  <pre><code>C c2=new C();
  B b2=new B();
  </code></pre>
  
  <p>So it should give the output of B's count as 1 and not 2.</p>