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 (Retired) Meet Objects Constructors

Brad Smeltzer
Brad Smeltzer
1,018 Points

I can't find my error in creating the constructor GoKart

Here's my attempt from the challenge:

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

public String getColor() { return mColor; } // here's where I'm attempting to create the constructor, but I get an error.

public GoKart(String color); { mColor = color; } }

Can anyone see anything obvious why this doesn't work? Thanks!

Brad

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

  public String getColor() {
    return mColor;
  }

  public GoKart(String color); {
    mColor = color;
  }
}

1 Answer

Rick Buffington
Rick Buffington
8,146 Points

You are spot on, however you have a small typo at the end of the constructor name/parameter declaration. There is no need for a semicolon at the end.

 public GoKart(String color); {        // <-- Get rid of the semi-colon

SHOULD BE:

 public GoKart(String color) {
Brad Smeltzer
Brad Smeltzer
1,018 Points

Thanks, Rick, for taking the time. I was getting extremely bugged by this challenge, but to find it was only the unnecessary semicolon was a great relief! I went back and pushed on through the rest of that set of challenges. I greatly appreciate it!