Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Creating the MVP Remaining Tries

"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??

Quinton Rivera
Quinton Rivera
5,177 Points

Im 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

2 Answers

Geovanie Alvarez
Geovanie Alvarez
21,500 Points

Static methods in Java can be called without creating an object of class.

is it necessary to create static?

Geovanie Alvarez
Geovanie Alvarez
21,500 Points

if you don't want to create an object yes

Tyler Combs
Tyler Combs
15,525 Points

It'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?