34.5k views
17 votes
Consider the following code snippet:

public class Score
{
private String name; . . .
public boolean equals(Object otherScore)
{
Score other = (Score) otherscore;
return name.equals(other.name);
} . . .
}
What is wrong with this code?
a) The return statement should use the == operator instead of the equals method.
b) The parameter in the equals method should be declared as Score otherScore.
c) It is an error to cast otherScore as a Score object before using the equals method
d) There is nothing wrong with this code.

User Kosoant
by
7.0k points

1 Answer

7 votes

Answer:

Programmatically: D, the code compiles fine

Step-by-step explanation:

The code compiles fine, although this is certainly a roundabout way of fulfilling this purpose.

User UcanDoIt
by
6.7k points