title: Java: How to Create an instance of a subclass from with a Static method of the super class
body: <p>My specific problem is that I want to create a static method in a base class which saves away the instances of the subclass in a file. And another static method in the base class which retrieves the data and recreates the instances of the subclass.</p>
  
  <p>I have got all of it working except where in my strategy I need to create an instance of the subclass within the static method of the base class. Please see what I mean below.</p>
  
  <p>And so the general question is in Java how do you Create an instance of a subclass from within a Static method of the superclass.</p>
  
  <pre><code>class Base
  
      public static Void saveAllInstances(){
         saveAttributesofAllInstancesInFile();  // this works
      }
  
      public static Void retrieveAllInstances(){
         destroyAllInstances(); // this works
         getInstanceAttributesFromFile();  // this works and returns e.g. ArrayList&lt;HashMap&gt;
  
         for( instanceAttributes : retrievedInstances ){
  
           // Here is the part I cant figure out: I want to create an instance of 
           // the subclass here 
           sub = new Sub();
  
           sub.setAttributes(instanceAttributes); //this works
         }
  }
  
  class Sub extends Base{
  }
  </code></pre>