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.
We'll cover the following...
Problem Statement
You have to implement a method GetDetails() in the Derived Class Beverage, which inherits from the Product class.
-
An auto-implemented property
Litersof typeintis declared in theBeverageclass. -
Modify the declaration of the
Beverageclass so that it inherits from theProductclass. -
In the implementation of
GetDetails()method, you must append and return theLitersalong with the corresponding beverage’s_nameand_pricevalues inherited from the base class, in the form of a string. -
We have already implemented the Base Class
Productwith the getters namely:GetName(int liters)- you have to pass the liters as a parameter to get the respective name of theBeverage)GetPrice(int liters)- you have to pass the liters as a parameter to get the respective price of theBeverage).
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"