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

Now change the color field to be private by adding the access level modifier.

Well does anyone have the solution to this problem.

I do not understand the question, and therefore am completely unable to solve the problem.

These lessons move to fast to learn everything they are talking about.

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

  public String getColor() {
    return mColor;

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

  }
}

The answer is: only add private with lowcase.

class GoKart { private String color = "red"; }

4 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

For this challenge, in this line public String mColor = "red";, all you need to do is change public to private.

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

  public String getColor() {
    return mColor;
  }
}

The answer is: only add private with lowcase.

class GoKart { private String color = "red"; }

None of these seem to work.

Muhammad Asif
PLUS
Muhammad Asif
Courses Plus Student 557 Points

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