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

Add a public constructor? Java

This is what i have,

class GoKart {
  private String color = "red";

  public String Color() {
    return color;
  }

}

  }

After being asked;

"First, define a public constructor that expects a String argument named color. (Don't worry about adding any code inside the constructor just yet, we'll do that next.)"

p.s it has been a few days since i did the lesson and i might need a reminder of the concepts.

Thanks.

2 Answers

Full disclosure: I don't know Java. I googled constructors for Java and I think this should do what you want:

class GoKart {
  private String color = "red";

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

thanks for your response

I'm not sure if your code will work but this passed the test thing, i clicked later and re watched the video on it.

here is the code that passed for reference ;

class GoKart {
  private String color;

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

  public String getColor() {
    return color;
  }

}