Articles → .NET → Liskov substitution principle in C#

Liskov substitution principle in C#






What does Liskov substitution principle say?





Example




public abstract class BaseClass {
  public abstract string GetWelcomeMessage(string message);
}

public class ChildClass: BaseClass {
  public override string GetWelcomeMessage(string message) {
    return string.Format("Welcome {0}", message);
  }
}






BaseClass baseClass = new ChildClass();
Console.WriteLine(baseClass.GetWelcomeMessage("Karan"));
Console.ReadLine();



Output


Picture showing the output of Liskov substitution principle in C#

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Monday, December 28, 2020

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250