CSA Unit 4 Lesson 6 Extra Practice

For U4 Lesson 6 Extra Practice, could somebody help me understand why C is the correct answer? C. crayon.equals(sharpie)

The equals() method in Marker class only defined what returns false, and it doesn’t have any command to return true based on the color instance variable of a Marker object.

In addition, E seems to be incorrect due to the “==”. Changing the “==” to .equals() would make E correct. - Is my understanding correct?

 return (temp.getColor().equals(this.color));

will return True if the color Strings of the two objects are equal.

If the color Strings are equal, the Marker objects are considered equal.

public boolean equals(Object other) {
    if (other == null) {
      return false;
    }

    Marker temp = (Marker) other;
    // If the color Strings are equal, the Marker objects are equal
    return (temp.getColor().equals(this.color)); 
    }

2 Likes

Got it. Thank you so much Sheck!

1 Like

@sheck - Kevin, thank you for addressing this post. Your response included a great explanation.
@zhu.xiaobo - Zhu, thank you for posting your question. There may be others with the same interpretation of this question, so this may help them explain this answer to their students.

Sylvia

1 Like