โ 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 function sound() that prints "Animal sound" and a virtual destructor. A derived class Cat publicly inherits from Animal. Your task is to override the sound() function in the Cat class so that it prints "Meow". The test will create a Cat object through a base class pointer and call sound(). Because sound() 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
Expected Output:
Meow
Topics:
Inheritance
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.