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 typeint
is declared in theBeverage
class. -
Modify the declaration of the
Beverage
class so that it inherits from theProduct
class. -
In the implementation of
GetDetails()
method, you must append and return theLiters
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 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"
Get hands-on with 1300+ tech skills courses.