Bird
Raised Fist0

Identify the error in this interface declaration:

medium📝 Debug Q6 of Q15
C Sharp (C#) - Interfaces
Identify the error in this interface declaration:
interface ICalculator { private int Add(int a, int b); }
AInterface names cannot start with 'I'.
BMethod name 'Add' is invalid in interfaces.
CInterface methods cannot have access modifiers like 'private'.
DMethod parameters are not allowed in interfaces.
Step-by-Step Solution
Solution:
  1. Step 1: Understand interface method rules

    Interface methods cannot specify access modifiers; they are implicitly public.
  2. Step 2: Identify the incorrect modifier

    The use of private on the method Add is invalid in an interface.
  3. Final Answer:

    Interface methods cannot have access modifiers like 'private'. -> Option C
  4. Quick Check:

    Interface methods are always public and cannot have access modifiers. [OK]
Quick Trick: Interface methods are implicitly public, no modifiers allowed [OK]
Common Mistakes:
MISTAKES
  • Adding access modifiers to interface methods
  • Assuming interface methods can be private or protected
  • Misunderstanding interface naming conventions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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