这个类型的程序怎么会抛出
NullPointerException异常
public class Array extends Student
{
public static void main(String args[])
{
Student[] st = new Student[10];
st[0].number = 1;
System.out.println(st[0].number);
}
}
class Student
{
public int number=1;
public int age;
}
我觉得就好象是 st[0].number =1 ;那里的错 , 敢问类类型的数组该怎么赋值啊 ?
------解决方案--------------------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;
}