title: Java Lock explanation
body: <p>I can't understand the following code:</p>
  <pre><code>   public class Counter {
        private long value;
        private Lock lock;
        public long getAndIncrement() {
         lock.lock();
         try {
          int temp = value;
          value = value + 1;
         } finally {
           lock.unlock();
         }
         return temp;
        }
      }
  </code></pre>
  <p>What I can't understand is how Lock is instantiated while it's an interface?
  And if it's an anonymous class that implements Lock interface, why I can't see any override of Lock functions (e.g. lock() and unlock() ) ?</p>
  <p>In short, the following line really confuses me.</p>
  <pre><code>  private Lock lock;
  </code></pre>
  <p>What is lock here? What is its type?</p>
  <p><strong>Edit:</strong></p>
  <p>Lock is an interface and can't be instantiated. After looking at the constructor:</p>
  <pre><code>public Counter(){
     lock = new ReentrantLock();
  }
  </code></pre>
  <p>Now, everything is clear. (Thanks to Bhushan Uniyal )</p>