This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Question taken from LearnKey MasterExam. Why is the set allowing duplicates, and showing the size as 2? I understand, it is because the equals() is not properly overridden, it doesn't take an Object. So, is the set allowing duplicate because of the equals() in Nearly class?
Thanks Ankit for your quick response. Is this what happens? calls equals() in the Nearly class. equals() and hashCode() are called before adding to HashSet. But here, the equals() called is of Object class(since Nearly class does not override equals() properly. So, n2 is added to the set. Please correct me if I'm wrong.