Bird
0
0

The following code causes a compilation error. What is the main reason?

medium📝 Debug Q14 of 15
C Sharp (C#) - Interfaces
The following code causes a compilation error. What is the main reason?
abstract class Shape {
  public abstract void Draw();
}

class Circle : Shape {
  public void Draw() {
    Console.WriteLine("Drawing Circle");
  }
}
ADraw() method must be static in Circle.
BAbstract classes cannot have abstract methods.
CCircle cannot inherit from Shape because Shape is abstract.
DCircle must declare Draw() as override, not just public.
Step-by-Step Solution
Solution:
  1. Step 1: Identify abstract method implementation rules

    When a class inherits an abstract method, it must override it using the override keyword.
  2. Step 2: Check Circle class method

    The Draw() method in Circle is declared as public void Draw() but missing override, causing a compile error.
  3. Final Answer:

    Circle must declare Draw() as override, not just public. -> 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 on abstract method implementation
  • Thinking abstract classes can't have abstract methods
  • Assuming static needed for overridden methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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