package Test;
import java.util.Arrays;
public class Test{
String name;
int price;
public static void main(String[] args){
Test[] a = new Test[2];
a[0].name = "jake";
a[0].price = 12;
a[1].name = "bob";
a[1].price = 15;
System.out.println(a);
}
}
>Exception in thread "main" java.lang.NullPointerException;
应该对每一个对象进行初始化
for (int i = 0; i < a.length; i ++) {
a[i] = new Test();
}