Bit of a strange one,
I actually have managed to answer a question by looking at examples and messing with my code but I don't actually understand fully how it is working!
Any explanation would be great and much appreciated!
Code:
I have a class called Player and 3 objects being created in another class in the main method.
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (obj instanceof Player) {
Player player = (Player) obj;
if (player.getName().equals(this.getName())) {
return true;
} else {
return false;
}
} else {
return false;
}
}