97,650 views
19 votes
19 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 Richard Cotrina
by
2.7k points

1 Answer

12 votes
12 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 Basi
by
3.2k points