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
195,561 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.