Test.java
package yiyonng;
import excise.CopyArrayAndOverReading;
import excise.Overreading1;
import excise.Overreading2;
import excise.yinyong;
public class Test {
public static void main(String[]args){
System.out.println("/////the exceriseof 7._1/////");
yinyong yin=new yinyong ();
yin.showyinyong();
//////////////////////////////////////////////
System.out.println("/////the exceriseof 7_2/////");
Overreading1 r1=new Overreading1();
r1.showoverreading1();
/////////////////////////////////////////////////
System.out.println("/////the exceriseof 7_3(overreading)/////");
Overreading2 r2=new Overreading2();
r2.showoverreading2();
/////////////////////////////////////////////////
System.out.println("/////the exceriseof 7_4(arraycopy)/////");
CopyArrayAndOverReading copy=new CopyArrayAndOverReading();
copy.showarraycopy();
}
}
CopyArrayAndOverReading.java
package excise;
import java.util.Arrays;
public class CopyArrayAndOverReading {
public void showarraycopy(){
int[] aa={1,2,3,4};
int[] bb={100,200,300,400};
System.arraycopy(aa,0,bb,0,aa.length);//复制length个元素
System.out.println("the values of bb");
System.out.println(Arrays.toString(bb));
}
}
Overreading1.java
package excise;
public class Overreading1 {
public void showoverreading1(){
int[] c={1,2,3,4};
char[] d={'a','b','c','d'};
for(int n=0;n
Overreading2 .java
package excise;
import java.util.Arrays;
public class Overreading2 {
public void showoverreading2(){
int []show1={1,2,3,4,5};
System.out.println(Arrays.toString(show1));//遍历数组,注意上面还有声明
}
}
yingyong.java
package excise;
public class yinyong {
public void showyinyong(){
int[] a={1,2,3,4};
int[] b={100,200,300};
System.out.println("there are"+a.length+" elements of a");
System.out.println("there are"+b.length+" elements of b");
System.out.println("address of a="+a);
System.out.println("address of b="+b);
System.out.println("a==b is "+(a==b));
a=b;
System.out.println("there are "+a.length+" elements of a");
System.out.println("there are "+b.length+" elements of b");
System.out.println("a==b is "+(a==b));
System.out.println("a[0]="+a[0]+",a[1]="+a[1]+",a[2]="+a[2]);
System.out.println("b[0]="+b[0]+",b[1]="+b[1]+",b[2]="+a[2]);
}
}
运行结果: