Where to declare global constants?
Hi;
If I have a project with a few java files and I want to declare a constant variable that all classes will have access to it, where do I write:
public static final int ROWS = 8;
thanks
[204 byte] By [
oh_crap] at [2007-11-11 8:17:51]

# 1 Re: Where to declare global constants?
You put your code in any of public classes.
// example
public class Test {
// a public static field
public static final int ROWS = 8;
public Test() {}
}
public class AppStart {
public static void main() {
System.out.println (Test.ROWS);
}
}
# 2 Re: Where to declare global constants?
Define a Constants interface and put all your constants which are shared by other classes. If that constant is specific to the class you are writing then store it in that class/interface itself.
arul at 2007-11-11 22:36:56 >
