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

Farouk Charkas
Farouk Charkas
1,957 Points

I also need help on this task!

So I have written the code below the question and I have been getting this error:

  '''
  ./GoKart.java:7: error: ';' expected
  String getColor() {
             ^
  ./GoKart.java:8: error: incompatible types: unexpected return          value
return color;
       ^

2 errors '''

Sorry if that was unclear but this is it: ./GoKart.java:7: error: ';' expected String getColor() { ^ ./GoKart.java:8: error: incompatible types: unexpected return value return color; ^ 2 errors

and I would like to know how to fix this! Thanks in advance!

GoKart.java
public class GoKart {
  private String mColor;

  public GoKart (String color) {
    mColor = color;

  String getColor() {
    return color;
  }
  }
}
Farouk Charkas
Farouk Charkas
1,957 Points

Yep that was the problem, thank you for coping with my bugging demands!

Farouk Charkas
Farouk Charkas
1,957 Points

Yep that was the problem, thank you for coping with my bugging demands!

2 Answers

Jon Kussmann
PLUS
Jon Kussmann
Courses Plus Student 7,254 Points
public class GoKart {
  private String mColor;

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

  public String getColor() {
    return mColor;
  }
}
Farouk Charkas
Farouk Charkas
1,957 Points

Yes, it took out some errors, so I added "String" between public and GoKart, that seemed to take off 1 of 2 errors, it then said "no return statement"

Jon Kussmann
Jon Kussmann
Courses Plus Student 7,254 Points

I wasn't very careful. I'll update the above answer

You should return "mColor" instead of "color" in your getColor() method.

Farouk Charkas
Farouk Charkas
1,957 Points

That did not help since the default workspace adds it for me, it still has the "No return statement"

Farouk Charkas
Farouk Charkas
1,957 Points

That did not help since the default workspace adds it for me, it still has the "No return statement"

Farouk Charkas
Farouk Charkas
1,957 Points

That did not help since the default workspace adds it for me, it still has the "No return statement"

Jon Kussmann
Jon Kussmann
Courses Plus Student 7,254 Points
public class GoKart {
  private String mColor = "red";

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

  public String getColor() {
    return mColor;
  }
}

I was able to complete the task with that.

Farouk Charkas
Farouk Charkas
1,957 Points

Oh maybe because I put string between public and GoKart

Farouk Charkas
Farouk Charkas
1,957 Points

Oh maybe because I put string between public and GoKart

Jon Kussmann
PLUS
Jon Kussmann
Courses Plus Student 7,254 Points

Hi Evering,

It looks like you have an extra "}". Try deleting the second to last one.

I hope that helps. If not please let me know.

Farouk Charkas
Farouk Charkas
1,957 Points

I appreciate your suggestion Mr. Kussman,

But no that does not work since I opened three code blocks but you suggested I end only two, that did not work for me.

Jon Kussmann
Jon Kussmann
Courses Plus Student 7,254 Points

You also have to add one right before you declare the getColor method. I'll paste what it should look like.