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 trial

Java Java Objects (Retired) Meet Objects Privacy and Methods

Not sure why my getter method isn't working. Please help!

Here is my code: public class GoKart { private String mColor = "red"; public String getmColor() { } return mColor; }

GoKart.java
public class GoKart {
  private String mColor = "red";
  public String getmColor() {
  } return mColor;
}

5 Answers

It's not working probably because your return statement is outside of the getmColor function. Move the return statement back inside of the curly braces and you should be good to go!

Prefixing an "m" to variables is a convention or self-documenting policy many developers use to indicate the variable, like mColor, is a "member variable" of the class, as opposed to a local variable. It is not required but appears to be the convention followed at Treehouse.

David, Thank you for your tip. I moved the return mColor statement to the inside of the getmColor function, and now I am getting a different error: " Bummer! The method name should match more or less your field name. Expected getColor." I am not sure what I am doing wrong here. This is a frustrating exercise and I don't think the video explained this concept well.

I removed the "m" from my getmColor method, so that it is just getColor. I am still confused as to why we are using "m" at all. This is super confusing and I don't think the video did a good job explaining why we are using this in the first place.

Yeah it can be confusing at times. Just stick with it and don't be afraid to look some stuff up on Google or something similar if you need help with a specific area quickly.

Did you get past your problem?

Yes I did get past this problem. Thanks for your help David!

If you want, since you got the problem sorted, you can choose my answer as best answer so people know the problem was solved! :)