Link to home
Start Free TrialLog in
Avatar of Samooramad
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?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Samooramad
Samooramad

ASKER

could i do the same with a list?
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

>> 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?
Any point will do
8-)