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

Colt Shelby
Colt Shelby
1,175 Points

Does the order of equations matter?

I found that the correct code for this challenge is:

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

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

  public String getColor() {
    return mColor;
  }
}

Originally I couldn't find the source of my error but I fixed it by switching

color = mColor;

to

mColor = color;

Why does the order of this matter?

No problem! :smile:

1 Answer

In algebra, "x = 0" is the same thing as saying "0 = x". However, for a computer (or at least for Java), you must keep the order like "x = 0" because it is easiest to read. :)

P.S.: I'm not sure if there's a programming language that allows "0 = x" syntax...you never know what there might be! :)

Hope that helps and happy coding!

Colt Shelby
Colt Shelby
1,175 Points

Okay! Thanks a lot!