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

I need help on the last code challenge involving java objects.

The complete question is: Now that you've created the GoKart class. Please create a new GoKart object using the GoKart class, or blueprint. As you know it takes a single parameter, color when being built.

I feel pretty stupid as I have looked up on previous forums how to write the code and I still am not passing. Others have put the correct code as:

GoKart goKart = new GoKart("red");

But I continue to get an error stating: Bummer! Please create a new GoKart object using the new keyword.

What is the new keyword, am I completely missing something obvious?

2 Answers

CJ Marchione
CJ Marchione
155,055 Points

Hi Taylor,

After testing out the challenge a little, I see that the error you mentioned occurs if you post the answer above the main method. Java's runtime system looks for code to be written within methods themselves (and main's the first one it evaluates.)

Concerning the new keyword, it is used when creating (instantiating) new objects of a class. In this case, we're specifying that we're creating a new GoKart object and naming it goKart. In this example we're also specifying a setting for its one parameter (the color, which we're making red.)

public class Example {

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

Hope this helps!

This works! Thank you so much for the help!