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

Problem with constructor exercise

class GoKart { private String color;

public String getColor() { return color; }

public String GoKart(String color) {

}

}

GoKart.java
class GoKart {
  private String color;

  public String getColor() {
    return color;
  }

  public String GoKart(String color) {

  }

}

2 Answers

Hi Linda,

Constructors don't have a verbose return value, i.e. they are silent as to what they return. They are named the same as the class and can take parameters, as you have done well. So, remove the String keyword between public and GoKart and you're good to go.

Steve. :smile:

Thank you, it really helped! I didn't see the difference between define a constructor vs method in the tutorial.

No problem! :+1: :smile: