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

Changing the access level modifier from public to private Task 1 of the challenge fails.

I am trying to solve this problem, what is my next step, I have listened to the video I know that I need to change the value "public String mColor = "red";" to "private String mColor = "red";" but when I this, result: Oops! It looks like Task 1 is no longer passing. What is my next step.

GoKart.java
public class GoKart {

  public String mColor = "red";
  //final private String mColor = "red";
    private String getColor() {
    return mColor;
  }
}

2 Answers

Hi Frederick,

Task 2 is looking for you to change the access modifier for the variable to private. The getter method will need to stay public.

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

  public String getColor() {
    return mColor;
  }
}

Thank you for you quick reply, The code you replied back with is what I used to complete Task 1. The challenge for me was how do I complete Task 2 with the following requirement?

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

if I change From: "private String mColor = "red";"

To: "public String mColor = "red";

this results in Task 1 failure message.

I kept on working on the problem: Here is the code that finally worked, the suggestion came from William Li almost 2 years ago: public class GoKart { private String mColor = "red";

// public constructor here public GoKart(String color) { mColor = color; }

public String getColor() { return mColor; } }

Thanks again for your help. -- fred