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

Naya Willis
Naya Willis
2,461 Points

what

What the hell am I doing wrong?

GoKart.java
public class GoKart {
  private String mColor;

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

1 Answer

When you set mColor to the color entered for the new GoKart, you don't need to use the word "new," since you're setting a variable (rather than creating a new object).

Naya Willis
Naya Willis
2,461 Points

but isn't constructors all about using the word new.

Yes, but that's not what that part of the code needs to do. If you are creating a new GoKart object, you'd say "new GoKart." However, mColor is a variable that you need to set to a value, so you do that by using "=" and the value you want to set it to.

Naya Willis
Naya Willis
2,461 Points

so how would the overall answer to the challenge look? Im not being lazy, i just want to know and study your answer because i been on this challenge for weeks now lol

If you just remove the "new" in front of "color," what you have should work!