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 trialharun west
1,732 PointsFinally, since the color is being set in the constructor now, remove the initialization from the field definition...
Finally, since the color is being set in the constructor now, remove the initialization from the field definition. Just leave it declared, but not initialized to "red".
I have absolutely no idea what this means. What is meant by "field", "initialization" and "declared"?
class GoKart {
private String color = "red";
//constructor
public GoKart(String color){
this.color = "red";
}
public String getColor(){
return color;
}
}
2 Answers
Fahad Mutair
10,359 Pointshi harun west ,
remove the initialization from the field definition
which means
private String color;
cherishli
654 PointsHey for anyone looking for help in 2020, here it goes. Just developing on Fahad's point:
You need to change the initial answer of: private String color = "red";
In the second line to -
private String color = "color";
Hope that helps.
harun west
1,732 Pointsharun west
1,732 PointsThank you for the answer Fahad. I changed private String color = "red"; to private String color;
but it still says color is still being assigned in the field declaration...?
Fahad Mutair
10,359 PointsFahad Mutair
10,359 Points