【发布时间】:2020-09-24 05:44:24
【问题描述】:
我该如何做这样的事情?我想采用像Circle 10 或Rectangle 20 30 这样的命令行参数并创建相应类的对象。
class Circle{
//Some lines here
}
class Rectangle{
//Some lines here
}
public class Perimeter{
public static void main(String[] args) {
for(int i=0; i< args.length; i++){
String shape = args[0];
shape curr_shape = new shape();
System.out.println(curr_shape.getPerimeter( <arguments> ));
}
}
}
【问题讨论】:
-
这能回答你的问题吗? Create new object from a string in Java
-
我已经创建了我需要的所有类。我需要使用变量创建这些类的对象。我认为该链接描述了如何使用字符串创建类。