Bird
0
0

Find the error in this code snippet:

medium📝 Debug Q7 of 15
C Sharp (C#) - Interfaces
Find the error in this code snippet:
interface ITest { void Run(); }
class Test : ITest { public void Run() { Console.WriteLine("Running"); } }
class Program { static void Main() { ITest t = new Test(); t.Run; } }
ANo error, code runs fine
BMissing parentheses when calling Run method
CMethod Run should be private
DInterface cannot be instantiated
Step-by-Step Solution
Solution:
  1. Step 1: Locate syntax error in method call

    Method invocations require parentheses (), even parameterless. t.Run; lacks them, causing compile error; correct is t.Run();.
  2. Final Answer:

    Missing parentheses when calling Run method -> Option B
  3. Quick Check:

    Method calls require parentheses [OK]
Quick Trick: Always use () to call methods, even without parameters [OK]
Common Mistakes:
MISTAKES
  • Omitting parentheses on method calls
  • Trying to instantiate interface directly
  • Making interface methods private

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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