Challenge 1: Implement the Derived Class

Can you Implement the Derived Class function by using the Base Class functions? A solution is placed in the solution section to help you, but we would suggest you try to solve it on your own first.

Problem Statement

You have to implement a method GetDetails() in the Derived Class Beverage, which inherits from the Product class.

  • An auto-implemented property Liters of type int is declared in the Beverage class.

  • Modify the declaration of the Beverage class so that it inherits from the Product class.

  • In the implementation of GetDetails() method, you must append and return the Liters along with the corresponding beverage’s _name and _price values inherited from the base class, in the form of a string.

  • We have already implemented the Base Class Product with the getters namely:

    • GetName(int liters) - you have to pass the liters as a parameter to get the respective name of the Beverage)
    • GetPrice(int liters) - you have to pass the liters as a parameter to get the respective price of the Beverage).

These getters return the name and price of the beverage.

Sample Input

Beverage cola = new Beverage();
cola.Litres = 1;

Sample Output

cola.GetDetails() = "Cola, 2, 1"

Get hands-on with 1200+ tech skills courses.