Bird
0
0

Identify the error in this code snippet:

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

Identify the error in this code snippet:

interface IA { void Run(); }
interface IB { void Jump(); }
class Player : IA, IB {
    public void Run() { Console.WriteLine("Running"); }
}
ARun method should be private.
BClass Player cannot implement two interfaces.
CInterfaces cannot have methods.
DClass Player must implement Jump method from IB interface.
Step-by-Step Solution
Solution:
  1. Step 1: Check interface methods

    IA requires Run(), IB requires Jump().
  2. Step 2: Verify class implementation

    Player implements Run() but misses Jump(), so it is incomplete.
  3. Final Answer:

    Class Player must implement Jump method from IB interface. -> Option D
  4. Quick Check:

    All interface methods must be implemented [OK]
Quick Trick: Implement all interface methods to avoid errors [OK]
Common Mistakes:
MISTAKES
  • Forgetting to implement all interface methods
  • Thinking interfaces can't have methods
  • Assuming methods can be private

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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