Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Meet Objects Creating New Objects

Oskar Pihlak
Oskar Pihlak
2,094 Points

Confused

I think I didn`t quite understand this. Watched the videos a couple times.

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



    }
}

Hi oskar,

like james say you need to create the object after public static void main(String[] args) { GoKart goKart = new GoKart("blue");

above the main method this place call class and this is where you set fields...hope it make sense for you :)

1 Answer

James Vaughan
PLUS
James Vaughan
Courses Plus Student 4,462 Points

Hi Oskar,

I've just had a look at the code challenge and I'm not sure what you've done in the source code above. The question provides you with:

public class Example {

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

The question then asks you to: create a new GoKart object using the GoKart class, passing a single parameter of the colour.

Adding the line:

GoKart goKart = new GoKart("blue");

Below the System.out... line should complete the challenge. That line means:

Create an object of type GoKart called goKart, use the constructer in the GoKart class to create this object and pass into that constructer the string "blue" (which is the colour).

Hope that helps.