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

Constructors Quiz Question 1.. Need serious help.

I felt like I understood the video and still couldn't finish the question even after trying multiple, multiple times to get it correct.

Question: 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.

What I got so far... (after multiple times of different code)

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

  public GoKart(); {

  }

  public String getColor() {
    return mColor;

  }
}

Also I also got an error...

./GoKart.java:4: error: missing method body, or declare abstract public GoKart(); { ^ 1 error

Im pretty sure I got the "Add a public constructor to the GoKart.java class... (Yet if Im wrong I dont mind being corrected)

I'm stuck on two other things. The " that allows the parameter color to be passed in."

Sure that means inside the parameter...

and the "In the constructor store the argument color in the private color field."

Now I'm sure the "In the constructor" is inside the code block.

Seems like in the video, I was fine, but when it came to for the quiz, I'm confused. I just need help. Thanks.

4 Answers

missgeekbunny
missgeekbunny
37,033 Points

You also need to create a variable to pass in such as

public GoKart(String color) {
}
Geovanie Alvarez
Geovanie Alvarez
21,500 Points

You have to remove the semicolon in the constructor

 public GoKart(); { // <---- here 

  }

Thanks both, I would like to give both best answer as both helped me, but malevolentbunny helped more with the color variable. Wow. Coding feel so rewarding ^_^

Upvoted both tho BTW.

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

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