package cn.ly.Day.seven.thirteen;
/*
* 首先创建一个长度为3的数组,里面用来存放3个Person对象
*数组有一个缺点,一旦创建,程序运行期间长度不可改变
* */
public class Demo02Array {
public static void main(String[] args) {
//首先创建一个长度为3的数组,里面用来存放Person类型的对象
Person [] array=new Person[3];
Person one=new Person("宜兴",12);
Person two=new Person("欢欢",2);
Person three=new Person("欢欢",2);
//将one当中的地址赋值到数组的0号元素位置
array[0]=one;
array[1]=two;
array[2]=three;
System.out.println( array[0]);
System.out.println(array[1]);
System.out.println(array[2]);
System.out.println(array[1].getName());
}
}

本文通过一个具体的Java程序示例,介绍了如何使用数组存储Person对象,并演示了对象的创建、数组的初始化及对象引用的赋值过程。同时,强调了数组长度在创建后不可更改的特点。
554

被折叠的 条评论
为什么被折叠?



