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!

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 trial

Java Java Objects (Retired) Creating the MVP Remaining Tries

I have a doubt that about static with final

Why are we using static with final in MAX_MISSES variable ? Is only final not enough to make MAX_MISSES constant ?

Simon Coates
Simon Coates
28,694 Points

static makes something a class variable, rather than to be bound to an instance.

2 Answers

Henrique Voni
Henrique Voni
12,296 Points

Static means that the MAX_MISSES property is a class property. Making it static lets you handle some logic when a object from that class is created.

shekhar bhardwaj
shekhar bhardwaj
Full Stack JavaScript Techdegree Student 12,373 Points

final indicates that the value of the variable won't change - in other words, a variable who's value can't be modified after it is declared. Use public final static String when you want to create a String that: belongs to the class (static: no instance necessary to use it), and that won't change (final), for instance when you want to define a String constant that will be available to all instances of the class, and to other objects using the class.