access public array in another class java code example
Example 1: how to access contents of an array from another class in java
class MyClass
{
//Variable I want to return
private int[] numArray = {1, 2, 3};
public int[] getNumArray() {
return numArray.clone();
}
}
Example 2: how can a class take array from another class in java
class B { int a; A obj = new A(); // Creating the Object of class A a = obj.arr[0]; // calling the array arr from that object System.out.println(a); }