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

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(); ?