Polymorphism Through Base Pointer
mediumQuestion 140You are given a base class Animal with a virtual function speak() that prints "..." and a virtual destructor.
Create two derived classes:
1. Dog - publicly inherits from Animal, overrides speak() to print "Woof"
2. Cat - publicly inherits from Animal, overrides speak() to print "Meow"
Both classes need constructors and properly overridden speak() functions. The test will create both objects through base class pointers to demonstrate polymorphism.
Do NOT include a main function. Your code will be tested automatically.
Expected output
Woof Meow
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
ClassesInheritance
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.