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 (Retired) Meet Objects Creating Classes

Chris Jones
Chris Jones
4,521 Points

Errors in the creating classes exercise?

Unsure where the errors are in my code. Says that you cannot start an expression with public and that cannot be correct.

GoKart.java
public class GoKart {
  public static void main (String[] args) {
    public String color = "red";
  }
}

3 Answers

The string color doesn't have to be public.

Chris Jones
Chris Jones
4,521 Points

Even when I take it out it doesn't pass.

It worked fine for me.

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Maybe this way ....

public class GoKart {
  public static void main (String[] args) {
     String color = new String ("red");
  }
}
Chris Jones
Chris Jones
4,521 Points

Ok I went back to refactor the code and it didn't want me to specify the public static void main line. It also asked me to use the member field specifier

String mGoKartColor = "red";