Hi Friends
Why are there no global variables in Java?
Global variables in Java
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Nov 20, 2012, 1:04 AM EST
However, you can effectively create global variables using public static fields. For example:
public class Global
{
public static int SomeVariable = 0;
}
You can then access the 'global' variable with the syntax Global.SomeVariable.