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

Creating object?

I don't really understand what this wants me to do... Do I have to create an entirely new GoKart and design it? What is the code it already displays?

Example.java
public class Example {

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

2 Answers

Florian Tönjes
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Florian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 Points

Yes, but you're still missing something. You have to tell the constructor which color the new GoKart should have.

Here is the GoKart class with it's constructor from the previous challenge:

public class GoKart {
  private String mColor = "red";

  // Constructor
  public GoKart(String color) {
    mColor = color;  
  }

  public String getColor() {
    return mColor;
  }
}

Regards, Florian

Florian Tönjes
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Florian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 Points

Hey Chang,

the challenge wants you to create a new instance of the 'GoKart' class that you had to design in the previous 'Constructors' challenge. The constructor takes a color as an argument that you pass in as a String.

Regards, Florian

So using new as in GoKart goKart = new GoKart(); ?