class Try
{
private int[] arr={1,2,3,4};
{
System.out.println(arr);
}
public void setArr(int[] arr)
{
if (this.arr.length!=arr.length)
{
System.out.println("请输入长度为4的数组");
return;
}
this.arr=arr;
}
public int[] getArr()
{
return arr;
}
}
class Test
{
public static void main(String[] args)
{
int[] arr = new Try().getArr();
System.out.println(arr);
Try t = new Try();
t.setArr(arr);
int[] arr1 = t.getArr();
System.out.println(arr1);
}
}
请分析一下内存 |