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 Meet Objects Add a Getter

Joshua Morillo
Joshua Morillo
2,562 Points

I'm stuck on the challange "Add a getter method that exposes the color field."

Hey,

I've been stuck on this challenge for a while now. I previously passed it but I didn't get to analyze what I did because the page loads to the points chart once you finish the last part of the challenge. I usually copy my code onto notepad before hitting check work but forgot this time. It keeps asking me if I forgot to return color but I'm sure I wrote the return part correctly. What am I missing? Any help would be greatly appreciated.

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

             }

1 Answer

It wants you to return a String. getColor is a method, not a String. In the first line of code you made a String called color that is equals to "red", so let's use that.

class GoKart {
  private String color = "red";
  public String getColor()
  {
    return color;
  }

You were so close!

Joshua Morillo
Joshua Morillo
2,562 Points

Right under my nose. Thank you!

No worries, be sure to upvote and to mark as best answer by clicking under my answer on the check mark.