public abstract class A {
   public string PublicPrint() { 
      return Print(); 
   } 
 
   protected virtual string Print() {
        return "A"; 
   } 
}
 public class B : A { } 
 public class C : B { 
     protected override string Print() { 
         return "C"; 
     } 
}
 
What will be the result of the following code execution?
 
A ac = new C(); 
Console.WriteLine(ac.PublicPrint());
 
Explanation
This question is about basic rule of polymorphism. Code is calling an overloaded method. This method must be marked as virtual in a base class and must have "override" keyword in its signature in derived class.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes