Junior — Middle
How is the default equals method usually created in Java?
sobes.tech AI
Answer from AI
By default, the equals method in Java, inherited from the Object class, compares objects by reference, meaning it returns true only if both variables point to the same object in memory.
Example of the default implementation:
public boolean equals(Object obj) {
return (this == obj);
}
If you want to compare objects by content, the equals method is usually overridden to compare the values of the class fields.