title: Generating unique auto-incrementing instance IDs
body: <p>I have been trying to generate unique IDs for class instances starting from 1, like so:</p>
  
  <pre><code>public abstract class foo {
      static int ID = 0;
      final int id;
  
      public foo() { this.id = ++ID; }
  }
  </code></pre>
  
  <p>I then realised that I have several classes that require this behaviour, and so I tried to make an <code>abstract class</code> from which to inherit, but I found that <code>static</code> fields can't really be inherited.</p>
  
  <p>Is there any way I can reuse this common behaviour in Java?</p>
  
  <p><em>Edit:</em><br>
  I did not make it clear, but I need the indexes for each subclass to be not only unique, but also consecutive.</p>
  
  <p>For example, if I have <code>bar</code> and <code>baz</code> inheriting from <code>foo</code>:</p>
  
  <pre><code>bar b1 = new bar();
  baz b2 = new baz();
  bar b3 = new bar();
  </code></pre>
  
  <p><code>b2</code> should have <code>id == 1</code>, and <code>b3</code> should have <code>id == 2</code>.</p>