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 IGreet { void SayHello(); }
class Person : IGreet {
public void SayHello() { Console.WriteLine("Hi!"); }
}
var p = new Person();
p.SayHello();
ANo output
BSayHello
CHi!
DCompile error
Step-by-Step Solution
Solution:
  1. Step 1: Understand interface and class

    The interface IGreet requires SayHello method. Person implements it by printing "Hi!".
  2. Step 2: Trace code execution

    Creating Person object and calling SayHello prints "Hi!" to console.
  3. Final Answer:

    Hi! -> Option C
  4. Quick Check:

    Implemented method runs and prints output [OK]
Quick Trick: Implemented method runs exactly as coded in class [OK]
Common Mistakes:
MISTAKES
  • Expecting method name printed instead of output
  • Thinking interface prints output
  • Assuming compile error without method body

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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