Solution Review: Override a Method in the Derived Class
This review provides a detailed analysis to solve the 'Override a Method in the Derived Class' challenge.
We'll cover the following...
Solution
Press + to interact
// Base Classclass Product {// Private Data Membersprivate string _className;public Product() { // Default Constructorthis._className = "Product";}// Getter Functionpublic virtual string GetName() {return this._className;}}// Derived Classclass XProduct : Product {private string _className;public XProduct(string className) { // Default Constructorthis._className = className;}// Overriden Methodpublic override string GetName() {return base.GetName() + ", " +this._className;}}class Demo {public static void Main(string[] args) {Product beverage = new XProduct("Beverage");Console.WriteLine(beverage.GetName());}}