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

Michel Bourgeois
Michel Bourgeois
731 Points

Add a getter method that exposes the color field.

I have been trying to add a simple getter method and return a color but does not work????? any ideas???? i m almost sure that the code is good but ????

GoKart.java
class GoKart {
  private String color = "red";

  public String getColor();
  {
    return  color;
  }
}
Nimish Chandola
Nimish Chandola
4,334 Points

i am having a problem in this code. There is error Did you forget to return color?

5 Answers

Michel Bourgeois
Michel Bourgeois
731 Points

Got it!!!!!! it was my semi colon that i erase and now it is working

Eugene Cidro
Eugene Cidro
1,546 Points

Thanks.. i figured it out too... semi colon after the open and close parenthesis..

The Answer is:

class GoKart { private String color = "red";

public String getColor() { return color; } }

Muhammad Asif
PLUS
Muhammad Asif
Courses Plus Student 557 Points

class GoKart { private String color = "red";

public String getColor() { return color; } }

I am still having trouble executing the code my code is as follows, can anyone please help me out here.

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

This code works besides the ; used after getColor()