Override equals method in JavaThe object class's equals() method, which accepts an object as well as compares it with the current object, is used to compare two objects. If the references to these two objects were equal, the method returns true; otherwise, it does not. Example The class Employee throughout the following example has two variables: name and age, as well as a parameterized function Object() { [native code] }. Using the equals() method, we create two objects from the main method by giving identical data and comparing the results. This software returns false because the Object class' equals() method only returns true if the references to the objects are identical. Example code for overriding the equals method: EqualsExpl.java Output: Overriding the equals() methodYou can develop your own version of the equals method since the Object is indeed the superclass for all Classes in Java. Example code: EqualsExpl1.java Output: Next TopicUndo and Redo Operations in Java |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India