Overloading,Overriding and Hiding? [closed]

Overloading is the definition of multiple possible “signatures” of a single method or operator. Each signature takes different arguments, and is essentially a distinct function, no different than if the multiple functions had different names. This is often used to group conceptually similar operations, such as overloading + to work with BigInteger and with String: both operations seem sensible to use + for (unless you think that all overloads of + should define Abelian groups — the String overload doesn’t).

Overriding is the definition of multiple possible implementations of the same method signature, such that the implementation is determined by the runtime type of the zeroth argument (generally identified by the name this in C#).

Hiding is the definition of a method in a derived type with a signature identical to that in one of its base types without overriding.

The practical difference between overriding and hiding is as follows:

  • If a method is overridden, the implementation to call is based on the run-time type of the argument this.
  • If a method is simply hidden, the implementation to call is based on the compile-time type of the argument this.

Leave a Comment