Bird
0
0

Identify the error in the following code snippet implementing explicit interface method:

medium📝 Debug Q14 of 15
C Sharp (C#) - Interfaces
Identify the error in the following code snippet implementing explicit interface method:
interface IAlpha { void Run(); }
class Beta : IAlpha {
    public void IAlpha.Run() {
        Console.WriteLine("Running");
    }
}
AExplicit interface method cannot have public modifier
BMethod name must be different from interface
CInterface name should not be used in method implementation
DMissing override keyword
Step-by-Step Solution
Solution:
  1. Step 1: Check explicit implementation rules

    Explicit interface methods must not have access modifiers like public; they are implicitly private.
  2. Step 2: Identify error in code

    The code uses public void IAlpha.Run(), which is invalid syntax for explicit implementation.
  3. Final Answer:

    Explicit interface method cannot have public modifier -> Option A
  4. Quick Check:

    Explicit methods = no public keyword [OK]
Quick Trick: Remove public from explicit interface methods [OK]
Common Mistakes:
MISTAKES
  • Adding public modifier to explicit methods
  • Confusing explicit with normal method override
  • Forgetting interface name in method signature

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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