Glossary / Method overrides

Method overrides

An override supplies a derived class implementation for an inherited virtual or abstract member. It participates in runtime dispatch and must match the base member's signature and accessibility constraints; the override keyword makes the intent explicit and compiler-checked.

Contracts and behavior

An abstract member must be overridden by a concrete derived class. An override can call base.Member() to reuse base behavior and may be sealed to prevent further overrides. It cannot change static-ness or reduce the member's accessibility. Covariant return types are supported in applicable C# versions for reference return types under runtime constraints.

An override should preserve the base contract, including null behavior, exceptions, side effects, and invariants. Calling base implementation is a design choice, not always required. Hiding with new is different: calls through base references still dispatch to the base virtual slot unless an override exists.

Interview questions

  1. What may be overridden? Members declared virtual, abstract, or already overridden, with supported member forms.
  2. Can an override change parameter types? No; it must match the base signature, aside from permitted covariant returns.
  3. What does sealed override do? Overrides the member and disallows further derived overrides.
  4. Must it call base? No; only when base behavior is intentionally part of the contract.
  5. Why honor base invariants? Derived implementations must remain substitutable wherever the base type is used.

References