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
PRO
Daniel Turato
Java Web Development Techdegree Graduate 30,108 Points

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