Java Object equals(Object obj) Methodequals(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. SyntaxParameterobj - it is the reference object. ReturnsIt returns true if this object is same as the obj argument else it returns false otherwise. Example 1Test it NowOutput: 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 2Test it NowOutput: 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
|