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

Vidmantas Varnas
Vidmantas Varnas
5,215 Points

Problems with task

Hello i have problems passing this, it always show me the bug that first part of the test is not passing, but the code looks fine :)

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

   public Gokart(String color){
     private String color;
     this.color = color;

   }
  public String getColor() {
    return color;
  }

}

2 Answers

the this.color is getting set in the [public Gokart(String color)] for color.

there no need to make a other [private String color;] and you can't call [private String this.color = "red";] on its self.

class GoKart {
  private String color;

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

}