Bird
Raised Fist0

Identify the error in this code snippet:

medium📝 Debug Q14 of Q15
C Sharp (C#) - Interfaces

Identify the error in this code snippet:

interface IShape {
  double Area();
}
class Circle : IShape {
  public double Area() {
    return 3.14 * radius * radius;
  }
}
AInterface method cannot return double
BMissing radius field or property in Circle class
CCircle class should not implement IShape
DArea method should be void
Step-by-Step Solution
Solution:
  1. Step 1: Check Circle class members

    The method Area uses 'radius' but no radius variable or property is declared in Circle.
  2. Step 2: Understand interface method return type

    Interface method returning double is valid; no error there.
  3. Final Answer:

    Missing radius field or property in Circle class -> Option B
  4. Quick Check:

    Undefined variable 'radius' causes error [OK]
Quick Trick: Check all variables used are declared [OK]
Common Mistakes:
MISTAKES
  • Thinking interface methods can't return values
  • Believing class can't implement interface
  • Assuming method return type must be void

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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