title: Java: Creating an Instance of a Subclass from the Superclass in a static method
body: <p>I am trying to create a new Instance of a subclass from my Super Class. This is my super class</p>
  
  <pre><code>public abstract class Worker {
  
      String world;
  
      protected abstract void onLoad(Scanner read);
  
      public static Worker load(Scanner read) {
          // I want to create the instance of my sub class here and call it w
          w.onLoad(read);
          return w;
      } 
  
      public void setWorld(String world) {
          this.world = world;
      }
  
  }
  </code></pre>
  
  <p>And this is my subclass</p>
  
  <pre><code>public class Factory extends Worker {
  
      @Override
      protected onLoad(Scanner read) {
          setWorld(read.readline());
      }
  
  }
  </code></pre>
  
  <p>And this is what I want to do with those classes.</p>
  
  <pre><code>public class MainClass{
  
      public List&lt;Factory&gt; loadFactories() {
          List&lt;Factory&gt; facts = new ArrayList&lt;Factory&gt;();
          Scanner read = new Scanner(new FileInputStream("factory.txt"));
  
          while(read.hasNextLine()) {
              Factory f = (Factory)Factory.load(read);
              facts.add(f);
          }
  
          read.close();
          return facts;
      }
  
  }
  </code></pre>
  
  <p>Is there any way I can do this without starting over? Thanks for any help.</p>