package October;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Scanner;
public class First {
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Scanner scan = new Scanner(System.in);
System.out.println("请输入类名:");
String name = scan.next();
Class cls = Class.forName(name);
Method[] methods = cls.getDeclaredMethods();
Object o = cls.newInstance();
for(Method method:methods) {
String methodName = method.getName();
if(methodName.startsWith("test")) {
method.invoke(o);
}
}
}
}
package October;
public class Cat {
public void testHello() {
System.out.println("hello");
}
void testTom() {
System.out.println("Tom");
}
void testKate() {
System.out.println("Kate");
}
void show() {
System.out.println("show");
}
}
1009-1
最新推荐文章于 2022-12-04 18:52:24 发布