title: Generic in Java with Interface
body: <p>I was reading the tutorial from <a href="https://docs.oracle.com/javase/tutorial/java/generics/types.html" rel="nofollow noreferrer">https://docs.oracle.com/javase/tutorial/java/generics/types.html</a>.</p>
  
  <p>Code:</p>
  
  <pre><code>public interface Pair&lt;K, V&gt; {
      public K getKey();
      public V getValue();
  }
  
  public class OrderedPair&lt;K, V&gt; implements Pair&lt;K, V&gt; {
  
      private K key;
      private V value;
  
      public OrderedPair(K key, V value) {
      this.key = key;
      this.value = value;
      }
  
      public K getKey()   { return key; }
      public V getValue() { return value; }
  }
  </code></pre>
  
  <p>But above code, i can't grasp.</p>
  
  <pre><code> Pair&lt;String, Integer&gt; p1 = new OrderedPair&lt;String, Integer&gt;("Even", 8);
      Pair&lt;String, String&gt;  p2 = new OrderedPair&lt;String, String&gt;("hello", 
     "world");
  </code></pre>
  
  <p>It seems like creating an object of Interface, but as per my understanding of OOP in c++, it's impossible to create an object of Abstract Class(My understanding is that Interface is somehow like Abstract Class). Needed a more specific answer "How is it possible to create such object?"</p>
  
  <p><strong>Edited</strong></p>
  
  <p>As i was suggested to view answer at <a href="https://stackoverflow.com/questions/16750772/instantiating-interfaces-in-java">Instantiating interfaces in Java</a>.</p>
  
  <p>What's the differences between instantiation of object in following two cases:</p>
  
  <pre><code>Pair&lt;String, Integer&gt; p1 = new OrderedPair&lt;String, Integer&gt;("Even", 8);
  OrderPair&lt;String, Integer&gt; p2 = new OrderedPair&lt;String, Integer&gt;("Even", 8);
  </code></pre>