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 Constructors

Add a public constructor to the GoKart.java class that allows the parameter color to be passed in. In the constructor st

I don't know how to do this thing, please help.

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

  public String getColor() {
    return mColor;
  }

  public GoKart gokart(String color){
    color = mColor;
    return mColor;
  }
}

2 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Hmm...I see a couple of problems.

The constructor seems to have the variable name that you want to create gokart in it. It does not need that. Also it looks like you are assigning the member variable to your argument, those seem flipped. And finally the constructor should not return, they just initialize your values.

Hope it helps! Keep at it!

Dear Craig,

Thanks a lot for your support, I figured it out my self before you reply :). I just have a small suggestion, if you can please add hints in the quizzes that would be great. Hints that are hidden by default and if we try and couldn't do it then we simply look at the hint.

Regards