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 trialDavid Santos
1,486 PointsAdd a public method, or getter, that can be used to get the color of the go kart. help i'm stuck
tried to add public getColor(){ return mColor()} but didn't work. Can anyone help please?
public class GoKart {
public String mColor = "red";
GoKart goKart = new Gokart("red");
public getColor(){
return mColor();
}
}
5 Answers
Jan Van Raemdonck
22,961 PointsYou forgot to add a return type to the definition of your method.
so it should be:
public String getColor(){
return mColor;
}
Also, don't try to create an object inside itself. So get rid of:
GoKart goKart = new Gokart("red");
inside of your GoKart class
David Santos
1,486 PointsThanks heaps bro Jan Van Raemdonck. Still confuse why you don't need to put parentheses though but it works ahaha.
Jan Van Raemdonck
22,961 PointsYou add parentheses when you are calling or defining a method. in this case we are just returning a variable, so no parentheses are needed.
Luis Santos
3,566 PointsI've tried everything and I still get it wrong, HELP!!!
jeremiahjacquet
16,885 PointsThe return type is missing for the answer. Missing String in this case after declaring accessor type "public" public String getColor()
David Santos
1,486 PointsThanks Bro Jan.
David Santos
1,486 PointsDavid Santos
1,486 PointsTks bro, but i have tried public class GoKart { public String mColor = "red"; public String getColor() { return mColor() ; } } before and didn't work. Any idea what i am missing?
Jan Van Raemdonck
22,961 PointsJan Van Raemdonck
22,961 Pointsah, i made a mistake in my answer, it should be
return mColor;
without parentheses. Sorry about that.
I edited my original answer