Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects Meet Objects Add a Constructor

Matthew Kramer
Matthew Kramer
619 Points

Why do the field and argument values need to be the same? I am already confused on the subject! Color VS color? WTF

Make sure the color you pass to Color is the same as the Value set by This.Color? What?????????????

GoKart.java
class GoKart {
  private String Color = "red";

  public GoKart(String color) {
    This.color = Color
  }

  public String getColor() {
    return color;
  }

}

1 Answer

Steven Parker
Steven Parker
215,939 Points

I think one point of this exercise is to be sure that you know how to differentiate a field and an argument if they have the same name. In actual practice, you would quite possibly choose a different name for one of them.

Notice that for this exercise, both names should be "color" (all lower case).

Also, the keyword "this" should always be all lower case.

Matthew Kramer
Matthew Kramer
619 Points

Not once did I see any mention to "This.color" needing to be lowercase. not even in the Bummer message. I was literally going insane trying to figure out why color was not equal to color. and color wasnt even the issue it was "this".

So infuriating... I thought I knew what was happening and now after this I am not sure anymore. Ugh.

Sorry.