What does the equals method compare in Java?

We know that whenever we create a new class, if the parent class is not specified, it inherits the object class by default.

If you do not override the equals method of the object class, when we call the equals method, we actually call the equals method inherited from the parent class.

So what exactly does the equals method compare? The document says: indicates whether another object is "equal" to this object.

Look at the code below:

Operation results:

It can be seen that the equals method in object actually compares and judges the addresses of objects to judge whether two objects have the same address.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>