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 trialLogan Detering
1,953 PointsI cant get past this step, please help
Please help
class GoKart {
private String color = "red";
public Gokart(String color){
color = red;
}
public String getColor() {
return color;
}
}
3 Answers
Joseph Frazer
5,404 PointsWhen you defined color you made it a string. Line 5 you assign it to an uncreated variable. If this still doesn't work please ask me :)
Joseph Frazer
5,404 PointsAlso, if your trying to set the string color equal to the parameter, do this:
class GoKart {
private String color = "red";
public Gokart(String color){
public this.color = color;
}
public String getColor() {
return color;
}
}
andren
28,558 PointsProbably just a bit of a typo on your end but variables inside methods / constructors does not use access modifiers (public, private, etc) that will cause the code to crash. They are only used for field variables, which are outside methods and belong to the class.
This is probably what you meant:
public Gokart(String color){
this.color = color;
}
Craig Dennis
Treehouse TeacherCheck the case between your constructor and the name of the class. They need to be exactly the same.
Hope that helps!