I’m a beginner in java, so I don’t know if there is any way to make a variable seen by all classes in same package?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine 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.
The default modifier (just don’t write
public/private/protected) gives access from inside the package only. (Take a look here)But as a rule, it is a good practice to avoid accessing variables directly.
Edit:
Responding the comments, if you want to access this variable without creating an object, then it should be static:
Then to access it, you need to qualify it by the class: