Hi Geek4Life,
Yes, it can be easily done, either by the constructor or by a setter.
Example :
Code:
public class Test1 {
private int[][] array;
public Test1(int[][] array) {
this.array = array;
}
...
}
public class Test2 {
private int[][] array;
public Test2() {
}
public void setArray(int[][] array) {
this.array = array;
}
}
public class Demo {
public static void main(String[] args) {
int[][] a = new int[1][1];
a[0][0] = 1;
Test1 t1 = new Test1(a);
Test2 t2 = new Test2();
t2.setArray(a);
}
} In my example, all the classes Demo, Test1 and Test2 will work
with the same object stored in memory.
If you mean to work with a replication of your array in order to preserve its initial values, then :
Code:
public class Demo {
public static void main(String[] args) {
int[][] a = new int[1][1];
a[0][0] = 1;
Test1 t1 = new Test1(a.clone());
Test2 t2 = new Test2();
t2.setArray(a.clone());
}
}