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

Dante White
Dante White
987 Points

I think there's a technical issue based on the questions my code should work public String GoKart(String color){ }

the question asked me to create a constructor that takes in String variable named color and to not put anything inside yet

my answer is:

class GoKart {

private String color;

public String GoKart(String color){

}

}

I keep having issues with the editor i have to play around with it in order for it to work even though the answer is the same it does work until i try 3 or 4 times

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

  public String GoKart(String color){

  }

  public String getColor() {
    return color;
  }

}

2 Answers

Thomas Nilsen
Thomas Nilsen
14,957 Points

Your issue is the constructor. That is not of type String (or any type for that matter):

public GoKart(String color){

}