第一题:
package test;
import java.util.Arrays;
import java.util.Scanner;
public class BeanFactory {
public static Object[] newInstance(){
Object[] objects=new Object[5];
for(int i=0;i<5;i++){
String className=new Scanner(System.in).nextLine();
try {
objects[i]=Class.forName("test."+className);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
return objects;
}
public static void main(String[] args) {
Object[] objects=BeanFactory.newInstance();
System.out.println(Arrays.toString(objects));
}
}
温馨提示:内容为网友见解,仅供参考