Look at the following class definition:
class Beverage:
def __init__(self, bev_name):
self.__bev_name = bev_name
Write the code for a class named Cola that is a subclass of the Beverage class. The
Cola class’s __init__ method should call the Beverage class’s __init__ method,passing ‘cola’ as an argument.
# Beverage class definition
class Beverage:
def __init__(self, bev_name):
self.__bev_name = bev_name
# Cola class definition, subclass of Beverage
class Cola(Beverage):
def __init__(self):
# Call the superclass (Beverage) constructor using super()
# Pass 'cola' as an argument to the Beverage class's __init__ method
super().__init__('cola')
# Create an instance of the Cola class and demonstrate its usage
def main():
# Create a Cola object
cola = Cola()
# Access the beverage name attribute using the superclass (Beverage) accessor method
print("Beverage Name:", cola._Beverage__bev_name)
# Call the main function to start the program
if __name__ == "__main__":
main()
Executed Output:
Beverage Name: cola