我不明白爲什麼I1.array [0] = 555是?我只是想改變ARR [0]初始化int數組
Intar I1 = new Intar(10);
int [] arr = I1.array;
arr[0]=555;
public class Intar {
int length;
int [] array;
public Intar(int lengt){
length=lengt;
array=new int[lengt];
Random ran =new Random();
for(int i=0; i<length; i++){
array[i]= ran.nextInt(100);
**當我改編之前和之後使用的System.out.println [0] = 555 **
I1.array [11, 57, 77, 74, 50, 62, 1, 11, 23, 27]
arr [11, 57, 77, 74, 50, 62, 1, 11, 23, 27]
After arr[0]=555
I1.array [555, 57, 77, 74, 50, 62, 1, 11, 23, 27]
arr [555, 57, 77, 74, 50, 62, 1, 11, 23, 27]
他們成爲同一個對象。 –