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

Still not working! About to just quite!

I still dont have a grasp on this. Maybe it's because I'm trying to convert the syntax from Code Academy to Treehouse's syntax. I don't know, I just need help!

Example.java
public class Example {
   GoKart mykart = new GoKart("blue");

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
    }
}

3 Answers

Hi,

I think I know what is wrong. When you were defining myKart you put GoKart instead of the public class name (Example). You could try the code below, I have changed it so it should be right.

public class Example {
   Example mykart = new Example("blue");

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
    }
}

I hope this helps.

Hi again,

I was mistaken when I wrote the last post. I have posted my code that I used for the quiz question, this should shoot you through.

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

I hope that this helps, if you have any problems or questions just shoot right back.

The reason your code is not working is because you're trying to create a new Example, although Example does not have a constructor.