Overriding rules in C#.NET — identify the correct statement about virtual/abstract methods and overrides. Select the statement that accurately reflects C# method overriding requirements.

Difficulty: Easy

Correct Answer: When overriding, the method name and full signature must exactly match the virtual member being overridden.

Explanation:


Introduction / Context:
Overriding in C#.NET lets a derived class provide a new implementation for a virtual (or abstract) member from a base class. Correct matching of signatures is essential.



Given Data / Assumptions:

  • We are dealing with instance methods in classes.
  • Focus is on virtual/abstract semantics and overriding rules.


Concept / Approach:
To override, a base member must be virtual/abstract, and the derived method must use the override keyword. The method's name, return type, and parameter types and order must exactly match (excluding optional parameters metadata differences). Static members cannot be virtual; abstract methods are implicitly virtual and must be overridden in a non-abstract derived class.



Step-by-Step Solution:

1) Check static: static cannot be virtual (so option A is false).2) Abstract methods are by definition virtual (option B is false).3) Overriding a virtual method is optional unless the method is abstract (option C is false).4) Overriding requires exact signature match (option D is true).5) Non-virtual methods cannot be overridden (option E is false).


Verification / Alternative check:
Compile small examples with and without matching signatures to see compiler diagnostics.



Why Other Options Are Wrong:
They contradict C# language rules on virtual and abstract members.



Common Pitfalls:
Confusing hiding (new) with overriding (override).



Final Answer:
When overriding, the method name and full signature must exactly match the virtual member being overridden.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion