Javatpoint Logo
Javatpoint Logo

Java Object equals(Object obj) Method

equals(Object obj) is the method of Object class. This method is used to compare the given objects. It is suggested to override equals(Object obj) method to get our own equality condition on Objects.

Syntax

Parameter

obj - it is the reference object.

Returns

It returns true if this object is same as the obj argument else it returns false otherwise.

Example 1

Test it Now

Output:

1st object created...
Addition of 10 and 20 : 
Answer : 30
2nd object created...
Addition of 10 and 20 : 
Answer : 30
Objects are equal:false

Example 2

Test it Now

Output:

1st object created...
Addition of 10 and 20 : 
Answer : 30
2nd object created...
Parameterized Constructors
Addition 2 and 3
Answer : 5
Objects are equal:false

Next TopicJava Object Class





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA