how to declare global variables in java?

Gooberlx2

Lifer
May 4, 2001
15,381
6
91
yes.

Make a constants class and declare only your vars (no methods).

public static final int BLAH_BLAH = 000;

Sure, it violates like every rule as far as variable/class access goes, but no one change them anyway since they're final.
 

Gooberlx2

Lifer
May 4, 2001
15,381
6
91
oh yeah, then access them via dot-notation something like:

for( int i=0; i < MyContants.BLAH_BLAH; i++) {
// some code here
}
 

Alex

Diamond Member
Oct 26, 1999
6,995
0
0
Originally posted by: Gooberlx2
oh yeah, then access them via dot-notation something like:

for( int i=0; i < MyContants.BLAH_BLAH; i++) {
// some code here
}

we haven't learned that yet but i can see how that works... sweet! :cool:


edit: boo for K&R notation :D