Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects Meet Objects Add a Getter

Julie Austin
Julie Austin
1,322 Points

It keeps asking if I forgot to return color but it's RIGHT THERE?!

I'm trying to add a public get string for the go kart color. My code looks the same as it did in practice but it keeps saying I forgot to return color and I'm super frustrated! I've rewatched the video like six times :(

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

1 Answer

Compare your code to that shown in the video @4:10

Some things to see:

  • There is no semicolon following the method name
  • The getter returns the private variable (in the video's case characterName) not the method name
Julie Austin
Julie Austin
1,322 Points

Thank you! Going back and knowing specifically what part of the video to check really helped. I could have sworn I started with that like 10 tries ago...oh well :/