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 trialBrian Watt
Courses Plus Student 457 PointsGetting the color from another method
im stuck at on this program, i believe i set it up right but i have two errors, please help
public class GoKart {
public String mColor = "red";
public String getColor();{
return mColor();
}
}
1 Answer
Ryan Duchene
Courses Plus Student 46,022 PointsTwo things. One, you only add semicolons at the end of a statement. The semicolon you have after getColor()
is causing an error.
Second, when you're returning a property like mColor
, you don't have to put parentheses after it. If you're calling a method, that's when you use the parentheses.
Fixed code:
public class GoKart {
public String mColor = "red";
public String getColor() {
return mColor;
}
}