Keyword: Subtype polymorphism, abstract classes, interfaces
EX00: Polymorphism
[Mandatory]
- For every exercise, you have to provide the most complete tset you can.
- Constructor and destructor of each class must display specific message.
- Don’t use the same message for all classes.
- Start by implementing a simple base class called Animal. It has one protected attribute:
- Implement a Dog class that inherits frm Animal.
- Implement a Cat class that inherits from Animal.
- These two derived classes must set their type field depending on their name.
- The Dog’s type will be initialized to “Dog”, and Cat’type to “Cat”
- The type of the Animal class can be left empty or set to the value of your choice.
- Every animal must be able to use the member function: makeSound()
- Running this code should print the specifit sounds of the Dog and Cat classes, not the Animal’s
- To ensure you understood how it wotks, implement a WrongCat class the inherits from a WrongAnimal class
- If you replace the Animal and the Cat by the wrong ones in the code above, the WrongCat should output the WrongAnimal sound.