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 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..