Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialOshedhe Munasinghe
8,108 Points"public static final int MAX_MISSES = 7;" static??
I dont understand what sir is saying about this: "public static final int MAX_MISSES = 7;"
why static? what is that for??
2 Answers
Geovanie Alvarez
21,500 PointsStatic methods in Java can be called without creating an object of class.
Oshedhe Munasinghe
8,108 Pointsis it necessary to create static?
Geovanie Alvarez
21,500 Pointsif you don't want to create an object yes
Tyler Combs
15,525 PointsIt's necessary to declare the constant static because we want the system to know that it won't ever vary when being called by other classes... right? In other words, I believe final means the value can never be <i>changed</i>, but static means it could also never be displayed as anything else?
Quinton Rivera
5,177 PointsQuinton Rivera
5,177 PointsIm a newbie but, if we didn't make the constant static, would the only other option to get the value inside of the static be to create a method that would return the value? i hope i am right at this logic.
Second question why did we set the constant to public, is that because if we would not be able to reference the constant value outside of its class if it is set to private? so should i always make static variables public because it seems like there would be no point of create an object to use a static variable