title: How can factory methods return instances of interfaces and abstract classes?
body: <p><a href="http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ExecutorService.html" rel="noreferrer">ExecutorService</a> and Service are interfaces and so only have abstract methods, which means that their methods are not implemented.  How then can we call, e.g., <code>future.get()</code>, <code>es.submit()</code>, and <code>es.shutdown()</code> methods on references of the interface type?  E.g., why can we do the following?</p>
  
  <pre><code>Future f = ...
  f.get();
  </code></pre>
  
  <p>Here's a more concrete example:</p>
  
  <pre><code>import java.util.concurrent.*;
  class Factorial implements Callable&lt;Long&gt; {
      long n;
      public Factorial(long n) {
          this.n = n;
      }
  
      public Long call() throws Exception {
          if (n &lt;= 0) {
              throw new Exception("for finding factorial, N should be &gt; 0");
          }
          long fact = 1;
          for(long longVal = 1; longVal &lt;= n; longVal++) {
              fact *= longVal;
          }
          return fact;
      }
  }
  
  class CallableTest {
      public static void main(String []args) throws Exception {
          long N = 20;
  
          Callable&lt;Long&gt; task = new Factorial(N);
          ExecutorService es = Executors.newSingleThreadExecutor();
          Future&lt;Long&gt; future = es.submit(task);
  
          System.out.printf("factorial of %d is %d", N, future.get());
          es.shutdown();
      }
  }
  </code></pre>