Bird
Raised Fist0

Identify the error in this code snippet:

medium📝 Debug Q14 of Q15
C Sharp (C#) - Polymorphism and Abstract Classes
Identify the error in this code snippet:
abstract class Shape {
    public abstract double Area();
}

class Circle : Shape {
    public double Area() {
        return 3.14 * 5 * 5;
    }
}
ACircle class cannot inherit from Shape.
BArea() method cannot return double.
CShape class cannot have abstract methods.
DCircle must declare Area() as override.
Step-by-Step Solution
Solution:
  1. Step 1: Check method overriding rules

    When a subclass implements an abstract method, it must use the 'override' keyword.
  2. Step 2: Identify missing override keyword

    Circle's Area() method lacks 'override', causing a compile error.
  3. Final Answer:

    Circle must declare Area() as override. -> Option D
  4. Quick Check:

    Override abstract method = must use 'override' keyword [OK]
Quick Trick: Override abstract methods with 'override' keyword. [OK]
Common Mistakes:
MISTAKES
  • Omitting 'override' keyword in subclass method.
  • Thinking abstract methods can be implemented without override.
  • Confusing return types.

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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