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 trialWeston Ross
832 PointsIm trying to add a public constructor to a class that allows the parameter to be passed in.
And in the constructor i need to store the argument color in the private field. I have followed the same pattern that has been shown in the previous video. But I am getting this error:
./GoKart.java:4: error: invalid method declaration; return type required public Gokart(String color){ ^ 1 error
Thank you for your help.
public class GoKart {
private String mColor;
public Gokart(String color){
mColor = color;
}
public String getColor() {
return mColor;
}
}
4 Answers
Pushpa Latha Rachamadugu
1,383 PointsHi,
Pls mathc the case of the class name GoKart ( this is your class) but constructor name is differnt .so it treating as method.
Pls change it and let me know if any issues
Vitor Freitas
3,579 PointsThe constructor need to have the same name as class, so the correct is 'GoKart' not 'Gokart'.
Weston Ross
832 PointsOh haha, silly me. I changed and it worked
Pushpa Latha Rachamadugu
1,383 Pointscool..Thanks for the updates.. Keep going...all the best
Pushpa Latha Rachamadugu
1,383 PointsPushpa Latha Rachamadugu
1,383 PointsHi,
Pls mathc the case of the class name GoKart ( this is your class) but constructor name is differnt .so it treating as method.
Pls change it and let me know if any issues