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

it look like I forgot to add the constructor..what am I missing?

I dont see what I am missing here..can anybody give me a clue?

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

  public String getColor() {
    return mColor;
  }
}

2 Answers

You need to add a constructor for the GoKart class that takes a parameter of a string called "color".

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

Tnx for your quick reply.. Looks like I got an assignment before I saw the video.. Got it now..

Afrid Mondal
Afrid Mondal
6,255 Points

Constructor means: you have to define a method exactly as same name as it's class. So, in your case the constructor name is GoKart(String color). A parameter name color to pass. Then assign value of this color parameter to your private string variable. Like this....

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

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

Tnx for your quick reply.. Got the assignment before the video somehow.. Got it now..