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 :(

5th Apr 2018, 7:55 PM
Edgar Oviedo
Edgar Oviedo - avatar
4 ответов
+ 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
5th Apr 2018, 8:26 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 1
You should post the code to make it more obvious for us to understand..
5th Apr 2018, 8:04 PM
Tomer Sim
Tomer Sim - avatar
+ 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
5th Apr 2018, 9:55 PM
Rabee Abbas
Rabee Abbas - avatar
0
thanks, I hope it works now :D
5th Apr 2018, 8:08 PM
Edgar Oviedo
Edgar Oviedo - avatar