Musical Instruments
You are developing an application for managing a musical orchestra's instrument inventory. You have to model different types of musical instruments and their actions.
You are asked to create a MusicInstrument class that has two attributes: name and type. This class should also have a method play() that prints "Playing the instrument".
Then, create a Guitar class that inherits from the MusicInstrument class (Guitar is of type String. This should be set automatically from the __init__ of Guitar). This class should have a method tune() that prints "Tuning the guitar". The play() method in the Guitar class should first call the tune() method and then calls play() from the parent class using super().
Create a Violin class in the same way as the Guitar class (it’s also of type String). The tune() method should print “Tuning the violin”.
Finally, create a Piano class that also inherits from the MusicInstrument class (Piano is of type Keyboard). The Piano class should override the play() method but it should not be tuned when played.
Input | Output |
|---|---|
| Tuning the guitar |
Note: The instrument's name and type attributes should be passed as parameters to the class constructor during instantiation. The play() method should be called without any parameters.
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB