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 trialFurquan Ahmad
5,148 PointsMy method is returning an error
I'm not sure why this method isn't working
public class GoKart {
public String mColor = "red":
public String getColorOfKart () {
return mColor;
}
}
10 Answers
Madison Finck
4,645 PointsIt is not getColorOfKart it is only supposed to be getColor: public class GoKart { public String mColor = "red";
public String getColor () {
return mColor;
}
}
Steven Donovan
13,281 Pointspublic class GoKart {
public String mColor = "red";
public String getColorOfKart () {
return mColor;
}
public static void main(String[] args) {
GoKart kart = new GoKart();
System.out.println(kart.getColorOfKart());
}
}
Steven Donovan
13,281 Pointsmain is the JVM entry point into your program. When you run java GoKart the JVM looks for the main method signature.
Steven Donovan
13,281 PointsIs that just one class from a bigger collection, or thats your entire program? If thats you're entire program then you're missing the main method
Furquan Ahmad
5,148 Pointshow would i do this sorry.
public class GoKart {
public static void main (String [] args) {
public String mColor = "red":
public String getColorOfKart () {
return mColor;
}
}
}
Furquan Ahmad
5,148 Pointsthat code doesn't work :/ Is there an error with this question ?
Steven Donovan
13,281 PointsYou had a : (colon) after "red" instead of required ; (semi-colon)
For the actual challenge you don't need the main, only the getColorOfKart method
public class GoKart {
public String mColor = "red";
public String getColorOfKart () {
return mColor;
}
}
Furquan Ahmad
5,148 Pointsthat code doesn't work :/ Is there an error with this question ?
Furquan Ahmad
5,148 Pointsthat code doesn't work :/ Is there an error with this question ?
Furquan Ahmad
5,148 Pointsthat code doesn't work :/ Is there an error with this question ?
Furquan Ahmad
5,148 Pointsthat code doesn't work :/ Is there an error with this question ?
Furquan Ahmad
5,148 Pointsthat code doesn't work :/ Is there an error with this question ?
Furquan Ahmad
5,148 Pointsthat code doesn't work :/ Is there an error with this question ?
Furquan Ahmad
5,148 PointsFurquan Ahmad
5,148 Pointssurely it shouldn't matter what the method is called, as i'm just creating the method
Furquan Ahmad
5,148 PointsFurquan Ahmad
5,148 PointsThis answer worked, but i really don't see what's the difference between my original code and yours, as you have just changed the method name !?