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

Charles Harpke
Charles Harpke
33,986 Points

Challenge 2 of 3

Encountering the following error in my code:

Bummer! Ensure that you assign the value passed into the constructor to this.color

GoKart.java
public class GoKart {
  private String Color = "red";

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

  public String getColor() {
    return Color;
  }
}

2 Answers

Seth Kroger
Seth Kroger
56,414 Points

The code you're given at the start already has a field named "color", not "Color". Changing it causes the challenge to fail. Starting variable name with a lowercase letter, not a capital letter is the proper convention anyway.

I passed the challenge with this

public class GoKart { private String Color;

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

public String getColor() { return color; } }