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

Eugenio Diaz
Eugenio Diaz
1,765 Points

I dont understand the question or how to do it. Could anyone explain? I am getting desperate.

Add a public method, or getter, that can be used to get the color of the go kart.

anyone??

I'd just like to remind you not to hesitate to ask questions. We are here to help and we enjoy doing it. (:

Eugenio Diaz
Eugenio Diaz
1,765 Points

Very nice forum! Very helpful, and you get he responses very fast!

3 Answers

Vrund Patel
Vrund Patel
11,994 Points

You need to create a method so that you can only get the value back and cannot change the value.

public class GoKart {
  public String mColor = "red";

  public String getColor(){
    return mColor;
  }
}

After that you need to make the instance private so it will be immutable

  private String mColor;

Hope this helps!

Devin Scheu
Devin Scheu
66,191 Points

Should look something like this:

public getGokart() {
    return [Object]
}
Eugenio Diaz
Eugenio Diaz
1,765 Points

Thank you very much! I was confused at first but now i get it!