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 trialarchie andrews
590 PointsWhat is wrong in this code
question is Let's ensure that all GoKarts created have a color. We'll solve this over a few steps.
First, define a public constructor that expects a String argument named color. (Don't worry about adding any code inside the constructor just yet, we'll do that next.)
class GoKarts {
private String color = "red";
public String GoKarts(String color){
}
}
3 Answers
Rumyana Dimitrieva
Java Web Development Techdegree Graduate 18,632 PointsHi Archie, constructor declarations look like method declarations—except that they use the name of the class and have no return type. In your code the constructor has a return type String.
Danny Oduro
298 Pointsclass GoKarts { private String color = "red";
public String GoKarts(String color){
}
}
mark niles
2,303 Pointspublic GoKarts(String color){ this.color = color; }
Raul Faure
596 PointsRaul Faure
596 PointsHi Archie, remember that the constructor uses the same name as the class? This is only a hint and I hope it helps...please let me know.