看到论坛一个朋友回答的一个问题 他写了这些代码public class Test {
public static void main(String args[]){
Student[] st = new Student[10];
st[0]= new Student();  //问题在这里 为什么要实例化对象后才能赋值,上面声明的数组的句子不是已经实例化对象了么?
st[0].number = 1;
System.out.println(st[0].number);
}
}
class Student{
public int number=1;
public int age;
}谢谢大家!

解决方案 »

  1.   

    Student[] st = new Student[10];//是Student对像数组可以放10个Students对像
    st[0]= new Student();
      

  2.   

    Student[] st = new Student[10];
    给你举个例子吧,这里只是给你10个可装32斤油的油壶,但是还没有装油
    下一步st[0]= new Student();  这个就是装油的过程.如果你只是Student[] st,这样就口头的跟你说,给你装32斤油的油壶,实际上一个油壶都没给,只是一句话,至于给多少,里面装不装油,那就是后面赋值时候给你了.
      

  3.   

    恩!都被说完了!我也没什么可说的了!
    Student[] st = new Student[10];
    这句只是定义了一个数组,并规定这个数组存储的内容的类型。但没具体定义里面的元素。
    st[0]= new Student();
    才是定义一个对象,并把引用赋值给st[0];