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 Meet Objects Add a Constructor

Jay Garcia
Jay Garcia
909 Points

Where am I going wrong here?

I have reviewed the video before this and cannot seem to find my error.

GoKart.java
class GoKart {
  private String color;

  public GoKart (String color){
    color = color;
  }

  public String getColor() {
    return color;
  }

}

1 Answer

K Cleveland
K Cleveland
21,839 Points
public GoKart (String color){
    color = color;
  }

Check out this part of the code. In your constructor, when you pass in "color", you're telling it to set "color" to "color". However, what you really want to do is make sure that this object will use the color value that get passed in.

Hopefully this helps! Good luck. :)

Jay Garcia
Jay Garcia
909 Points

Thank you. I found the answer shortly after I posted this but did not know how to remove the question.