Challenge 1: Override a Method in the Derived Class

Can you override a method in a derived class? A solution is placed in the solution section to help you, but we suggest you try to solve it on your own first.

Problem Statement

When a method in a derived class overrides a virtual method in a base class, it is still possible to call the overridden method using the base keyword.

If you write base.Method(), it will call the method that was defined in the superclass.

The GetClassName() method is already implemented in the base class.

You are given a partially completed code in the editor. Modify and override the method GetClassName() in the derived class code so that the code returns the following:


Derived Class Name


Base Class Name, Derived Class Name

Sample Input

         Product beverage = new XProduct("Beverage");

Sample Output

         "Product, Beverage"

Get hands-on with 1200+ tech skills courses.