????2??????????????
public class NewObject
{
String name;
public NewObject()
{
System.out.println(“ the object is created!”);
}
public void write()
{
System.out.println(“”);
}
}
??????????′??????????????
try
{
no=(NewObject)Class.forName(className).getConstructor(String.class).newInstance(names);
//no=(NewObject)Class.forName(className).getConstructor(newObject[]{String.class}).newInstance(names);
}
catch(IllegalArgumentExceptione)
{
e.printStackTrace();
}
catch(SecurityExceptione)
{
e.printStackTrace();
}
catch(InstantiationExceptione)
{
e.printStackTrace();
}
catch(IllegalAccessExceptione)
{
e.printStackTrace();
}
catch(InvocationTargetExceptione)
{
e.printStackTrace();
}
catch(NoSuchMethodExceptione)
{
e.printStackTrace();
}
catch(ClassNotFoundExceptione)
{
e.printStackTrace();
}
????3?????????????????
????public class NewObject
????{
????String name;
????public NewObject(String name)
????{
????this.name = name;
????System.out.println(“ the object is created!”);
????}
????public void write()
????{
????System.out.println(this.name);
????}
????}
??????????′??????????????
try
{
Constructor[] cs;
cs = Class.forName(className).getConstructors();
Constructor cc = Class.forName(className).getConstructor(String[].class);
no = (NewObject)cc.newInstance(new Object[]{names});
}
catch (SecurityException e)
{
e.printStackTrace();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
catch (NoSuchMethodException e)
{
e.printStackTrace();
}
catch (IllegalArgumentException e)
{
e.printStackTrace();
}
catch (InstantiationException e)
{
e.printStackTrace();
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
catch (InvocationTargetException e)
{
e.printStackTrace();
}