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

I don't understand "Please create a new GoKart object. As you know it takes a single parameter, color"? Please explain.

I am having trouble understanding "Please create a new GoKart object. As you know it takes a single parameter, color."? I tried some code but it's not correct. Please help. I don't know what code or where to place my code.

Example.java
public class Example {

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

1 Answer

Hi Mark,

I guess this challenge continues on from either a previous one or from the course itself. I don't know as I've done neither.

Essentially, it is relying on you knowing that the constructor for the GoKart class creates a nrw instance of a GoKart and requires one parameter which is a string representation of a colour.

So, the line of code that does this would look something like:

GoKart redKart = new GoKart("Red");

That declares a variable of type GoKart before the equals sign, allocating a GoKart-sized chunk of memory for that purpose then, after the equals sign, initializes the variable by executing the constructor which then fills the chunk of memory with the instance of a GoKart which is "Red".

That code should be placed after the println statement in the challenge.

I hope that makes sense.

Steve.