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

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 :/