Why does an overridden function in the derived class hide other overloads of the base class?

Judging by the wording of your question (you used the word “hide”), you already know what is going on here. The phenomenon is called “name hiding”. For some reason, every time someone asks a question about why name hiding happens, people who respond either say that this called “name hiding” and explain how it works … Read more

What’s wrong with overridable method calls in constructors?

On invoking overridable method from constructors Simply put, this is wrong because it unnecessarily opens up possibilities to MANY bugs. When the @Override is invoked, the state of the object may be inconsistent and/or incomplete. A quote from Effective Java 2nd Edition, Item 17: Design and document for inheritance, or else prohibit it: There are … Read more

What issues should be considered when overriding equals and hashCode in Java?

The theory (for the language lawyers and the mathematically inclined): equals() (javadoc) must define an equivalence relation (it must be reflexive, symmetric, and transitive). In addition, it must be consistent (if the objects are not modified, then it must keep returning the same value). Furthermore, o.equals(null) must always return false. hashCode() (javadoc) must also be … Read more

what are the methods “public override bool equals(object obj)” and “public override int gethashcode()” doing? [closed]

Most types in .NET derive from the type System.Object, simply called object in C#. (E.g. interfaces don’t, however their implementations do.) System.Object declares the methods Equals and GetHashCode as well as other members. (Note: The case matters in C#). The types you create automatically inherit these methods. The task of Equals is to compare an … Read more