Solution: Polymorphism Trace

Output

15
I got this!
10
When are office hours?
30
I got this!
25
When are office hours?
d3
d2
d1

Why

Class behavior recap

First loop (Question* p[2])

Static type is Question*, so getValue() calls Question::getValue().

Second loop (NonTrivialQuestion* q[2])

Static type is NonTrivialQuestion*, so getValue() calls NonTrivialQuestion::getValue().

Destructor output

Only delete p[1]; is called. Because the destructor is virtual:

DifficultQuestion::~DifficultQuestion() -> d3
NonTrivialQuestion::~NonTrivialQuestion() -> d2
Question::~Question() -> d1