package ch4;
/**
* Created by Jiqing on 2016/11/9.
*/
public class ArrayInRam {
public static void main(String[] args) {
int[] a = {5,7,20};
int[] b = new int[4];
System.out.println("b数组的长度为:"+b.length);
for(int i = 0,len = a.length;i<len;i++) {
System.out.println(a[i]);
}
// 循环输出b数组的元素
for (int i = 0,len = b.length;i<len;i++) {
System.out.println(b[i]);
}
// b引用指向a引用的数组
b = a;
System.out.println("b数组的长度为:"+b.length);
for (int i = 0,len = b.length;i<len;i++) {
System.out.println(b[i]);
}
a[1] = 11;
System.out.println(b[1]); // 值变了
}
}
package ch4;
/**
* Created by Jiqing on 2016/11/9.
*/
public class Person {
public int age; // 年龄
public double height; // 身高
public void info() {
System.out.println("我的年龄是:"+age+",我的身高是:"+height);
}
}
package ch4;
/**
* Created by Jiqing on 2016/11/9.
*/
public class Student {
public static void main(String[] args) {
Person[] students;
students = new Person[2];
Person zhang = new Person();
zhang.age = 15;
zhang.height = 158;
Person lee = new Person();
lee.age = 16;
lee.height = 161;
students[0] = zhang;
students[1] = lee;
lee.info(); // 我的年龄是:16,我的身高是:161.0
students[1].info(); // 我的年龄是:16,我的身高是:161.0
}
}
本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/6048370.html,如需转载请自行联系原作者