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