JavaBeginner#object#fundamentals

What is the difference between == and equals() when comparing objects that don't override equals()?

If a class doesn't override equals(), it inherits Object's implementation, which behaves identically to ==, comparing references rather than logical content.

Example
class Point { int x, y; }
Point p1 = new Point();
Point p2 = new Point();
p1.equals(p2); // false, same as p1 == p2, since equals() isn't overridden

Related Questions

1
JavaIntermediate#object#hashmap

What is the purpose of the hashCode() method and its contract with equals()?

Open
2
JavaBeginner#fundamentals

What is the instanceof operator?

Open
3
JavaBeginner#fundamentals#java10

What is the difference between var and explicit typing in Java 10+?

Open