What must be done so that the JVM understands whether toll and toll2 are the same or not ?
1.) Override public boolean hashCode() in Toll
2.) Override public int hashCode() in Toll
3.) Override public boolean toString() in Toll
4.) Override public boolean equals() in Toll
5.) Override public boolean equals(Object o) in Toll
The corret answers are 2) and 5), and the explication for the author is:
"The equals and hashCode methods must be overridden to compare any 2 objects"
But for me the unique answer correct is the number 5).
It is not clear what is meant by "JVM understands" but assuming that the question is trying to compare the contents of the objects, option 5 is correct. Of course, as Jeanne said, it is a good practice to override hashCode if you are overriding equals, but from a strictly comparison perspective, overriding hashCode is not required.