0
How can I use the same array in two classes?
I have 2 classes, I create an array once and I want use that array in the other class, but it doesn't work, How can I do that?, please help me :(
4 Respostas
+ 1
the solution to this should be the static keyword.declare your array as static in the first class.
class Boy{
public static int []num={6,7,8};
}
class Two{
piblic int []num2=Boy.num;
}
not sure I did this right,but I know the static keyword is the solution
+ 1
You should post the code to make it more obvious for us to understand..
+ 1
don't forget to consider access modifiers (public , private, .....)in some languages if you don't specify access modifier explicitly, the compiler will assign private to it , this may be the cause of the problem
0
thanks, I hope it works now :D