Bird
Raised Fist0

Why does a derived class in C# sometimes use the new keyword before a method declaration instead of override?

hard🧠 Conceptual Q10 of Q15
C Sharp (C#) - Inheritance
Why does a derived class in C# sometimes use the new keyword before a method declaration instead of override?
ATo call the base class method explicitly
BTo override a sealed base class method
CTo make the method static
DTo hide a base class method without overriding it
Step-by-Step Solution
Solution:
  1. Step 1: Understand difference between 'new' and 'override'

    'override' replaces a virtual method; 'new' hides a method with the same name without overriding.
  2. Step 2: Explain use case for 'new'

    When the base method is not virtual or you want to hide it intentionally, 'new' is used to declare a new method in the derived class.
  3. Final Answer:

    To hide a base class method without overriding it -> Option D
  4. Quick Check:

    'new' keyword hides base method, not override it [OK]
Quick Trick: 'new' hides base method; 'override' replaces it [OK]
Common Mistakes:
MISTAKES
  • Using 'new' to override virtual methods
  • Confusing 'new' with calling base method
  • Assuming 'new' makes method static

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes