← Back to Inheritance
Question 130
Base Pointer to Derived Object
Base Pointer to Derived Object
A base class Animal has been provided with a virtual functionsound()that prints "Animal sound" and a virtual destructor. A derived class Cat publicly inherits from Animal. Your task is to override thesound()function in the Cat class so that it prints "Meow". The test will create a Cat object through a base class pointer and callsound(). Becausesound()is virtual, the derived version will be called. This is called polymorphism. Do NOT include a main function. Your code will be tested automatically.
Expected Output:
Meow= newline. The output ends with a newline — print one after the last line.
Hints2 available
Sign in to use hintsTopics:
Inheritance
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.