Java Java Objects Meet Objects Add a Constructor

David O'Mahoney
David O'Mahoney
869 Points

Question 2 of challenge task for creating a constructor.

Hello, this is my answer for number 2 of the challenge task, can anybody advise where I'm going wrong?

GoKart.java
class GoKart {
  private String color = "red";
  public GoKart(String name){
    color = name;
  }
  public String getColor() {
    return color;
  }

}

1 Answer

Your parameter should be called color instead of name, then set it as a field like:

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