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 New Objects

Print out using System.out.printf the color of the new object, using the getColor method. Pleas help.

I get error at GoKart color = new GoKart(); ^

public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
      GoKart color = new GoKart ("red");
        System.out.printf("New Gokart is %s\n", color.getColor());
  public class GoKart {
    private String mColor;

    public GoKart (String color) {
      mColor = color;

    public String getColor() {
      return mColor;

1 Answer

Hi there Stevan Popov , the reason why it points that error is this

 GoKart color = new GoKart ("red");

there is a space after GoKart that shouldn't be there. So that needs to change to...

 GoKart color = new GoKart("red");

In addition to that the extra classes you added below were not asked from you so you might like to remove that from there. According to the java language specification, there can be only one public class in a file and the file name should be the same as the public class name. So you can't put two public classes in the same file as that will give you an error of its own and if you check the editor it will be stating " error: class GoKart is public, should be declared in a file named GoKart.java public class GoKart {" so you definitely should remove the GoKart class and your issues will be solved :)

Thanks gloria , but how do i make getColor method if i can't make a new file like in video?

You are welcome. I believe that is already coded behind the scenes. That happens in several code challenges. If you were in another editor or in workspaces you'll need to create that class in another file for it to run though, but in this code challenge it is not asked for.

Omg i did not know that thanks so much. xD

Ha ha, it's all right, now you know. You are welcome Stevan.