Dynamically load a child class?
<p>I need to create instances of classes by class name, the problem is that these classes happen to be child classes(I already have an instance of the parent class). I remember class.forName() cannot load child class. In C++ I could use a look-up table from name to static function pointers to do this, but is this dynamic child class loading even possible in Java?</p>

<p>Thank you.</p>

<p><strong>UPDATE</strong></p>

<p>Thanks for the answer, but it looks it doesn't work for the following example:</p>

<p>AbStractTest.java</p>

<pre><code>public abstract class AbstractTest{
      AbstractTest(int i){}
      class InnerTest
      {
             InnerTest(){
                 System.out.println("inner test class");
             }
             void test(){
                 System.out.println("inner test");
             }
      }
}
</code></pre>

<p>Test.java</p>

<pre><code>public class Test extends AbstractTest
{
      Test(int i){
          super(i);
      }
      public static void main(String[] args) throws Exception
      {
             Test t = new Test(1);
             AbstractTest.InnerTest innerTest = (AbstractTest.InnerTest)Class.forName("AbstractTest$InnerTest").getConstructor(AbstractTest.class).newInstance(t);
             innerTest.test();
      }
}
</code></pre>

<p>It ends up the following error:</p>

<pre><code>Exception in thread "main" java.lang.NoSuchMethodException: AbstractTest$InnerTest.&lt;init&gt;(AbstractTest)
        at java.lang.Class.getConstructor0(Class.java:2678)
        at java.lang.Class.getConstructor(Class.java:1629)
        at Test.main(Test.java:9)
</code></pre>
