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

I don't know what to delete from this code challenge, anything i do delete it comes back with an error. Plz Help

I read the question over and over trying to figure out what to delete, but I just cannot find it. Everything that I have deleted has either come back with an execution error or an incomplete error.

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

  public String getColor() {
    return color;
  }
  public GoKart(String color){
    this.color = color;
  }
}

Try making sure that your constructor is the first method.

class GoKart {

  private String color = "red";

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

  public String getColor() {
    return color;
  }

}

2 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

it's just asking you to not initialize the color, but only to declare it. a declaration is like String name;to initialize is to give a beginning value, whereas the declaration just creates the variable and it has no beginning value. so to initialize my name example, i could put name = "jon"; to do both in one line is what you have right now, like String name = "jon"; so just roll it back from an initialization to being just a declaration and it will pass.

At line 2 you are declaring the color ('private String color') and setting it to red (' = "red"'). Now that you have the correct constructor you want to set the color only in the constructor. Keep the part of line 2 where you declare the variable, and delete the part where you assign it to the value "red". Post you code here if you still have issues.