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 trialBethany Brewer
3,177 PointsHelp please! I can't get pass this error: Bummer! Ensure that you assign the value passed into the constructor to this.
As mentioned I can't seem to get pass that error. I'm stumped. Any help would be much appreciated. Thanks
public class GoKart {
private String mColor = "red";
public GoKart(String color){
mColor=color;
}
public String getColor() {
return mColor;
}
}
2 Answers
xiaoluke
6,387 PointsI believe in the new Java Objects course (it was recently refreshed) you use instead :
private String color = "red";
public goKart(String color){
this.color = color;
}
this.color refers to the color of the object and color is the value passed in via the constructor.
Bethany Brewer
3,177 PointsSolved thank you both!
Alex Bratkovskij
5,329 PointsAlex Bratkovskij
5,329 PointsLuke is right, this.color = color; will be frivate cuz u cant really call it, its assigned jsut to the construcor.
P.S. Luke, try using ``` java before u put your code in, it will make it shiny and ez to read :) look