对象数组的声明有两种方式
Java 引用的默认值为null,所以在创建对象数组后,数组内部各个引用的值都为零值即null
一,先定义,再开辟空间
先构造了一个类StudentOfSoftware;
声明数组如下:
类名称 对象数组名[] = null;
对象数组名 = new 类名称[长度];
StudentOfSoftware students[] = null;
students=new StudentOfSoftware[5];
二,定义并开辟数组
同样先构造了一个类StudentOfSoftware;
创建数组方法如下:
类名称 对象数组名[] = new 类名称[长度];
StudentOfSoftware students[] = new StudentOfSoftware[5];