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 Constructor

Finally, since the color is being set in the constructor now, remove the initialization from the field definition...

Finally, since the color is being set in the constructor now, remove the initialization from the field definition. Just leave it declared, but not initialized to "red".

I have absolutely no idea what this means. What is meant by "field", "initialization" and "declared"?

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

  //constructor
  public GoKart(String color){
    this.color = "red";
  }

  public String getColor(){
    return color;
  }

}

2 Answers

hi harun west ,

remove the initialization from the field definition

which means

private String color;

Thank you for the answer Fahad. I changed private String color = "red"; to private String color;

but it still says color is still being assigned in the field declaration...?

class GoKart {
  private String color;

  //constructor
  public GoKart(String color){
    this.color = color;
  }

  public String getColor(){
    return color;
  }

}

Hey for anyone looking for help in 2020, here it goes. Just developing on Fahad's point:

You need to change the initial answer of: private String color = "red";

In the second line to -

private String color = "color";

Hope that helps.