I want to declare global variables so I can use them anywhere in my project. How do I achieve that?
Question
Share
Sign Up to our social questions and Answers to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers to ask questions, answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no global variable in Java. However, we have a static keyword that we can use to define a global variable by doing something like the below:
But be careful because if this class gets unloaded, you will end up with an undefined null error that is difficult to catch.