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

Nathan Huls
Nathan Huls
5,709 Points

First, define a public constructor that expects a String argument named color. (Don't worry about adding any code inside

The hint is telling me to make sure my constructor is the same name as the class. I am not seeing the issue here.

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

  public String GoKart() {
  }
}

2 Answers

Hi Nathan,

It wants a String argument; you have it returning a String.

Arguments go inside the brackets. The constructor returns nothing but is silent, so there's no need to put the void keyword there. Something like;

public GoKart(String color){
  // make a GoKart!
}

I hope that helps,

Steve.

Nathan Huls
Nathan Huls
5,709 Points

Thanks Steve, that absolutely helped.

Steven Couture
Steven Couture
2,106 Points

As Mr. Hunter said before, you have it returning a string but what you should be doing is having it take a string argument. F.Y.I. constructors don't return anything, they are meant to initialize class members and/or take arguments.