CJCoding With Joseph
15free / daySign inCreate account

Polymorphism Through a Base Reference

Virtual dispatch works through base REFERENCES, not only pointers.

Base class Speaker has a virtual method string speak() const returning "...".

Create a derived class Human that overrides speak() to return "Hello".

The runner binds a Speaker& reference to a Human and calls speak() through it. Because speak() is virtual, the program prints the output shown in Expected Output.

Do NOT write a main function.

Expected Output:

Hello

= newline. The output ends with a newline — print one after the last line.

Hints2 available
Topics:
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.