Thursday, March 12, 2009

Does java support global variables (CoreJava)

Question :Does java support global variables? (CoreJava)
Answer :Though java doesn't support global variables, you can achieve this by
creating variables public and static.
Example
public class Global {
public static int x = 37;
public static String s = "test";
}
Such members can be accessed by saying:
public class test {
public static void main(String args[])
{
Global.x = Global.x + 100;
Global.s = "bbb";
}
}

No comments: