Bird
0
0

Examine the code below and identify the issue:

medium📝 Debug Q6 of 15
C Sharp (C#) - Polymorphism and Abstract Classes
Examine the code below and identify the issue:
abstract class Appliance {
    public abstract void TurnOn();
}
class Blender : Appliance {
    public void TurnOn() {
        System.Console.WriteLine("Blender is on");
    }
}
AThe method TurnOn should be static in the abstract class.
BThe class Blender cannot inherit from an abstract class.
CThe abstract class Appliance cannot have abstract methods.
DThe method TurnOn in Blender must use the override keyword.
Step-by-Step Solution
Solution:
  1. Step 1: Check method overriding rules

    Since TurnOn is abstract in Appliance, any subclass must override it explicitly.
  2. Step 2: Verify method signature

    Blender's TurnOn method matches the signature but lacks the override keyword.
  3. Final Answer:

    The method TurnOn in Blender must use the override keyword. -> Option D
  4. Quick Check:

    Abstract methods require override in subclasses [OK]
Quick Trick: Abstract methods require override keyword in subclass [OK]
Common Mistakes:
MISTAKES
  • Forgetting to use override keyword on abstract method implementations
  • Thinking abstract classes cannot have abstract methods
  • Assuming inheritance from abstract classes is disallowed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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