import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Test15
{
public static void main(String[] args
{
Class clazz= Class.forName("com.itheima.Sample");
Constructor constructor = clazz.getConstructor();
Sample s = (Sample) constructor.newInstance();
Method method = clazz.getMethod("getinfo");
method.invoke(s);
}
}
|
|