title: static factory method in interface class java
body: <p>I was reading <strong>Effective java</strong> text book. First item is about using static factory methods instead of public constructor. My doubt is that if i am specifying an <code>Interface</code> how can i specify a static factory method in the <code>Interface</code> ? Because java does not support static methods inside <code>interface</code>. The text book specifies about creating a <strong>non-instantiable class</strong> containing the public static factory methods. But how can those method access the private constructor of the implementation class?</p>
  
  <p>The text book says if you are defining an <code>Interface Type</code> , create a non-instantiable class <code>Types</code> and include the static factory methods in that class. But how can a method defined in the <code>Types</code> class access the private constructor of a concrete implementation of <code>Interface Type</code></p>
  
  <p>EDIT:- Below sentence is quoted from the text book. Please explain me its meaning</p>
  
  <p>"Interfaces can’t have static methods, so by convention, static factory methods for an interface named <em>Type</em> are put in a noninstantiable class (Item 4) named <em>Types</em> "</p>
  
  <p>EDIT:- taken from <a href="https://stackoverflow.com/questions/6129026/effective-java-by-joshua-bloch-item1-static-factory-method">Effective Java By Joshua Bloch: Item1 - Static Factory Method</a></p>
  
  <pre><code>     public interface Foo{ //interface without plural 's' (question 1)
       public void bar();
   }
   public abstract class Foos(){ // abstract factory with plural 's' (question 1)
      public static Foo createFoo(){
          return new MyFoo();
      }
      private class MyFoo implements Foo{ // a non visible implementation (question 2)
         public void bar(){}
      }
   }
  </code></pre>
  
  <p>My question is that how can the static method <code>createFoo()</code> calls the private constructor of <code>MyFoo</code> </p>