Samooramad
asked on
global variable
hey everyone
I have a variable I want to use in 2 classes ( or two files to be exact) is it possible by just declaring it public?
can i access it normally?
I have a variable I want to use in 2 classes ( or two files to be exact) is it possible by just declaring it public?
can i access it normally?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
also i would want to access its elements one at a time. does that change anything? are they accessed with a n index [i] like an array?
>>could i do the same with a list?
Yes. If your method is called getList then you'd do
Object o = getList().get(0); // get first element
Yes. If your method is called getList then you'd do
Object o = getList().get(0); // get first element
ASKER
>> public String getSomeString() {
return someString;
does it make any difference where i put the method?
does somestring (or my list rather) need to be declared at a certain point in my code?
return someString;
does it make any difference where i put the method?
does somestring (or my list rather) need to be declared at a certain point in my code?
Any point will do
8-)
ASKER