Bird
Raised Fist0

What will happen if you try to compile this code?

medium📝 Predict Output Q5 of Q15
C Sharp (C#) - Interfaces
What will happen if you try to compile this code?
interface ITest { void Run(); }
class Test : ITest { }
ACompilation error: 'Test' does not implement 'Run()'
BCompiles successfully
CRuntime error when calling Run()
DWarning but compiles
Step-by-Step Solution
Solution:
  1. Step 1: Verify interface implementation rules

    Classes implementing an interface must provide all member implementations. Test declares : ITest but lacks Run(), causing compilation error: 'Test' does not implement 'Run()'.
  2. Final Answer:

    Compilation error: 'Test' does not implement 'Run()' -> Option A
  3. Quick Check:

    Missing interface method implementation = compile error [OK]
Quick Trick: Implement all interface methods or get compile error [OK]
Common Mistakes:
MISTAKES
  • Assuming empty class compiles
  • Expecting runtime error instead
  • Ignoring interface method requirements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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