Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q13 of 15
C Sharp (C#) - Interfaces
What will be the output of this code?
interface IExample { void Show() => Console.WriteLine("Default"); }
class Test : IExample { }
var t = new Test();
t.Show();
ARuntime error
BCompilation error: Show() not implemented
CDefault
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Check if class implements Show()

    Class Test does not implement Show(), but interface provides default implementation.
  2. Step 2: Understand default method usage

    Since Test inherits IExample, it uses the default Show() method from interface.
  3. Final Answer:

    Default -> Option C
  4. Quick Check:

    Default method runs if not overridden [OK]
Quick Trick: If not overridden, default interface method runs [OK]
Common Mistakes:
MISTAKES
  • Assuming missing implementation causes error
  • Expecting runtime error without override
  • Thinking interface methods can't have bodies

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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