Difficulty: Easy
Correct Answer: override
Explanation:
Introduction / Context:
Polymorphism in C#.NET relies on virtual methods in a base class and overriding implementations in derived classes. This question checks knowledge of the correct modifier used when providing a new implementation.
Given Data / Assumptions:
Concept / Approach:
Use the override
keyword in the derived class to replace the virtual method’s implementation. The base class marks the method as virtual
(or abstract
), while new
would hide rather than override.
Step-by-Step Solution:
public virtual void M()
, then Derived must write public override void M()
to override.Using virtual
in the derived class would declare a new virtual method rather than overriding without override
.Keywords like overloads
and overridable
are VB.NET terms, not C# modifiers; base
is used to call the base implementation, not to declare an override.
Verification / Alternative check:
Try calling a method via a base-class reference that points to a derived instance; only an override
participates in dynamic dispatch.
Why Other Options Are Wrong:overloads
and overridable
are not C# keywords; virtual
alone is insufficient in the derived class; base
is not a modifier.
Common Pitfalls:
Confusing method hiding (new
) with overriding, or mixing VB.NET keyword vocabulary with C#.
Final Answer:
override
Discussion & Comments