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 trial

Java Java Objects Harnessing the Power of Objects Add a Constant

creating constants in a code

how do you create a constant in code

GoKart.java
class GoKart {
  public static final int MAX BARS GOKARTS = 8;
  final private String color;

  public GoKart(String color) {
    this.color = color;
  }

  public String getColor() {
    return color;
  }

}

4 Answers

....thanks very much most appreciated

Stanley Thijssen
Stanley Thijssen
22,831 Points

You can not have spaces in your variable names. The right naming convention in this case will be: MAX_BARS.

... the code is showing errors

Daniel Turato
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
Daniel Turato
Java Web Development Techdegree Graduate 30,124 Points

Stand naming conventions for constants are as followed : MAX_BARS_GOCARTS . So, the name needs to be capitalised with underscores separating individual words