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 trialManik Mehra
1,877 PointsNow in the body of your constructor, set the private field color to the value of the color argument passed into the cons
I am not ABLE TO FIGURE OUT the problem in my code.....Please help.
Thank you
public class GoKart {
private String mColor = "red";
private String mColor = "red";
public GoKart(String color) {
mColor = color;
}
}
4 Answers
Evan Demaris
64,262 PointsHi Manik,
Kirill is correct, to add to his answer though; your code declares and assigned mColor twice, although the Challenge doesn't ask for a variable called mColor
to be created at all. You'll want to use this
to clarify the color
variable scoped to the method vs the color
variable scoped to the class; this
in a method references the object whose context the method is running in.
class GoKart {
private String color = "red";
public String getColor() {
return color;
}
public GoKart(String color) {
this.color = color;
}
}
Hope that helps!
Kirill Dakhnyuk
7,073 PointsHi, change mColor to color, then in constructor you need to use RIGHT color which you declare in private field. You need to use THIS. So... public GoKart (String color) { this.color = color; }
Yakir Haviv
Courses Plus Student 1,117 Pointsclass GoKart { private String color = "red";
public String getColor() { return color; } public color(String color) { this.color = "red"; }
}
Prince Chinyadza
6,333 Pointsclass GoKart { private String color = "red"; public color(String color) { this.color = color; }
public String getColor() { return color; }
}