Junior — Middle
How is the comparison of objects via equals() implemented in the Object class?
sobes.tech AI
Answer from AI
In the Object class, the equals() method is implemented to compare objects by reference, meaning by default it checks whether two references point to the same object in memory. The implementation is roughly as follows:
public boolean equals(Object obj) {
return (this == obj);
}
This means that without overriding equals(), references are compared, not the contents of the objects. To compare the contents, classes usually override this method, implementing logic to compare fields.