Overriding equal method | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Overriding equal method

how to override equal method?what are the steps needed?

31st Oct 2017, 10:10 AM
oyl
1 Answer
+ 1
equals is a method from "Object" the root of every object created (even yours) so you dont need to extend or implement extra things...how to override a function? for equals it would look like this @Override public boolean equals(Object o){ // your code } be carefull! equals takes a Object so you can put anything inside it, to write a correct equals you have to check if the types of the objects even match and then cast "o" to your desired objecttype .. to refere to your object use "this"
31st Oct 2017, 12:21 PM
Chrizzhigh
Chrizzhigh - avatar