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

Error: Return outside of Method Java Can any help me grasp what and where the method for this code is and are

I had quite a few errors with this code and I've weed most of them out but i can't seem to get this last compiler error to go away I've placed it in many places around the code but still seems to error out and when i watch the video over again the answer still seems to escape my grasp. I'm gonna go watch it again maybe ill get it eventually

GoKart.java
public class GoKart {
  public String mColor = "red";
}

This is My Code IDK if it showed up here in the post

public class GoKart {
  public String mColor = "red";
  public String getMColor; {
    return mColor; 
  }
}
habtezion dawit
habtezion dawit
1,918 Points

i seem to be stuck in the same place, i can't seem to figure out how to add a "public method" or a "getter" to get the color of the go kart, were you able to figure it out in the end?

1 Answer

Ben Deitch
STAFF
Ben Deitch
Treehouse Teacher

Hey Fredrick! It looks like you've got a semi-colon after your function name 'getMColor;'. After the function name would be where we specify any parameters, but if they're aren't any parameters (like in this case), then we just want to put parentheses. So instead you should be using 'getMColor()'. Hope that helps!