Jan-31-2020, 02:14 PM
Hi community,
I am trying to implement some polymorhphism concepts. In the study material I am using, there is a similar example. There is no __init__ method in the sample example.
I want to define 2 types of flowers - one which can be cleaned only by spraying some water and others where the petals need to cleaned one by one.
Depending on the subclass, I want the appropriate method to be invoked. Below is my code and below is the error, can you please help:
I am trying to implement some polymorhphism concepts. In the study material I am using, there is a similar example. There is no __init__ method in the sample example.
I want to define 2 types of flowers - one which can be cleaned only by spraying some water and others where the petals need to cleaned one by one.
Depending on the subclass, I want the appropriate method to be invoked. Below is my code and below is the error, can you please help:
class Flowers: def cleaningTask(): pass def performCleaningTask(): cleaningTask() class petalFlowers(Flowers): def cleanThePetals(): print("petals are cleaned") def cleaningTask(): cleanThePetals() class sprayFlowers(Flowers): def sprayWater(): print("only water is sprayed") def cleaningTask(): sprayWater()
Error:>>> rose=petalFlowers()
>>> rose.performCleaningTask()
Traceback (most recent call last):
File "<pyshell#67>", line 1, in <module>
rose.performCleaningTask()
TypeError: performCleaningTask() takes 0 positional arguments but 1 was given