233k views
0 votes
public class BaseballTeam { private String city, mascot; private int numberOfPlayers; @Override public boolean equals(Object obj) { if ( !(obj instanceof BaseballTeam)) return false; BaseballTeam other = (BaseballTeam) obj; return (city.equals(other.city) && mascot.equals(other.mascot)); } @Override public int hashCode() { return numberOfPlayers; } }

1 Answer

5 votes

Complete Question:

The Complete Question is on the image uploaded below:

Answer:

The answer is

C. The class compiles but has an improper hashCode() method.

Step-by-step explanation:

The complete explanation for the answer above is shown on the first and second uploaded image

public class BaseballTeam { private String city, mascot; private int numberOfPlayers-example-1
public class BaseballTeam { private String city, mascot; private int numberOfPlayers-example-2
public class BaseballTeam { private String city, mascot; private int numberOfPlayers-example-3
User Sandeep Vokkareni
by
7.4k points