填充数组..创建和我开发的应用程序最简单的方法
class Wheel {
private int size;
Wheel(int s) {
size = s;
}
void spin() {
System.out.print(size + " inch wheel spinning, ");
}
}
public class Bicycle {
public static void main(String[] args) {
Wheel[] wa = { new Wheel(15), new Wheel(17) };
for (Wheel w : wa)
w.spin();
}
}
但是请提醒,我们怎么能在更简单的术语表达Wheel[] wa = { new Wheel(15), new Wheel(17) };
。
请务必查看Java Collections API。集合优于数组,因为集合(Set,List等)更容易处理。 – rob 2012-04-29 06:55:04