public class Test{
public static void main(String[] args){
Student[] stu = new Student[20];
for (int i = 0; i < stu.length; i++){ stu[i] = new Student();
.......
【完整代码如图】
为什么这部分(粗体)一定需要写呢?去掉后就会出错。
前面不是已经new Student[20]了吗,为什么还要在循环体中一个个new啊?
...全文
77416打赏收藏
Java有关类数组的初始化问题
public class Test{ public static void main(String[] args){ Student[] stu = new Student[20]; for (int i = 0; i < stu.length; i++){ stu[i] = new Student(); ....... 【完整代码如图】 为什么这部分(粗体)一定需要写呢?去掉后就会出错。 前面不是已经new Student[20]了吗,为什么还要在循环体中一个个new啊?