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

help

Add a public constructor to the GoKart.java class that allows the parameter color to be passed in. In the constructor store the argument color in the private color field.

my code:

public class GoKart {
  private String mColor = "red";

  private GoKart.java(String color) {
   mColor = color;
  }

  public String getColor() {
    return mColor;
  }
}

http://teamtreehouse.com/library/java-objects/meet-objects/constructors-2

Lyric Abbott , also I suggest you write more descriptive titles when writing your question. Part of the title suppose to explain what kind of help you need. Thank you.

2 Answers

Add a public constructor to the GoKart.java class that allows the parameter color to be passed in. In the constructor store the argument color in the private color field.

you need to make the constructor public since the task asked for that to be the access modifier

constructors in java generally look like this:

public ClassName() {
// do stuff
}

remove the .java from your constructor and make the method public

public GoKart(String color) {
   mColor = color;
  }
Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Lyric;

If you look at about the 1 minute mark in the video Mr. Dennis shows the example and gives the instruction.

Also, for future posts, please follow the instructions on this link for posting code.

Ken