Bird
0
0

Given this code, what will be printed?

hard🚀 Application Q8 of 15
C Sharp (C#) - Polymorphism and Abstract Classes
Given this code, what will be printed?
class Base {
    public virtual string Info() => "Base Info";
}
class Derived : Base {
    public override string Info() => base.Info() + " & Derived Info";
}
class Program {
    static void Main() {
        Base obj = new Derived();
        System.Console.WriteLine(obj.Info());
    }
}
ABase Info
BBase Info & Derived Info
CDerived Info
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Understand override calling base method

    The Derived override calls base.Info() and appends its own string.
  2. Step 2: Analyze output of method call

    Calling Info() on obj (runtime type Derived) returns "Base Info & Derived Info".
  3. Final Answer:

    Base Info & Derived Info -> Option B
  4. Quick Check:

    Override can call base method and extend output [OK]
Quick Trick: Override can call base method using base keyword [OK]
Common Mistakes:
MISTAKES
  • Expecting only derived or base output
  • Ignoring base.Info() call
  • Thinking override replaces base call

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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