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 Harnessing the Power of Objects Changing State

nikhil davasam
nikhil davasam
2,182 Points

why is GoKart not taking as a identifier?

not able to execute the program.what is the correct syntax

class GoKart {
  public static final int MAX_BARS = 8;
  private String color;
  private static void  int barCount(GoKart){


  public String getColor() {
    return color;

2 Answers

Dear Nikhil ,

I would recommend to go back and watch previous videos , to strengthen knowledge about those concepts since they are the fundamental building blocks for Java language.

1st : static and void (are only method and class keywords , as far as I'm concerned) so they can be omitted.

2nd : The variable should have '()' since it's not a method / constructor / function

3rd : That leaves us with :

private int barCount; 

and one thing to note : you're missing a class constructor to set initial values for the properties of your object

so the complete code should look like this :

public class GoKart { 

// Class field declaration 
private static final int MAX_BARS = 8;
private String color;
private int barCount

// Constructor for the class
public GoKart(String color) {
this.color = color;
barCount = 0;

// Declare the charge method 
public void charge() {
barCount = MAX_BARS


So this is how the final answer should look like I encourage you to practice more till you get the hang of things , I know Java can be a very verbose language , but it has it's own pro's and cons as well as a steep learning curve and I wish you the best of luck. for further question you can message me at twitter @itz_pauz