... It works for me.
Here's the full code I'm using:
public class Test
{
public static void main(String[] args)
{
String classname = "t1";
try
{
Class<?> test = Class.forName(classname);
Object o = test.newInstance();
if (o instanceof t1)
{
((t1) o).print();
}
}
catch (ClassNotFoundException exception)
{
// TODO Auto-generated catch block
exception.printStackTrace();
}
catch (InstantiationException exception)
{
// TODO Auto-generated catch block
exception.printStackTrace();
}
catch (IllegalAccessException exception)
{
// TODO Auto-generated catch block
exception.printStackTrace();
}
}
}
and the t1 class:
public class t1
{
public void print()
{
System.out.println("t1 works");
}
}