How can I tell an object how many times it has been created?

I have a class that has an attribute called int nth_instance and I want it to count the how many created object it is. ( I’m really sorry for the bad english, I don’t know how to describe this, but I hope you get my point).

Here’s my approach.

class K{     static int nth_instance;     K(){      nth_instance++; // here's the problem, every other instance gets the     }                 //  same value       public static void main(String[] args){      K k1 = new K(); // This object should have nth_instance set to 1      K k2 = new K(); // n_th_instance should be 2, but k1 is now also 2    }  } 

So the problem is that every instance of K gets the nth_instance value of the last created object.