Skip to main content Link Search Menu Expand Document (external link)

Duck Typing Quiz

Question

How many distinct fight functions does the compiler create?

3 because fight is called with 3 different types

Correct!

1 because all 3 types define the same method defeat

A template is instantiated separately for each different type with which it is used. fight is called with 3 types: GuardianApe, GreatShinobiOwl and IsshinTheSwordSaint, so the compiler creates 3 instances.

3 because it instantiates fight with type available

A template is instantiated separately for each different type with which it is used. fight is called with 3 types: GuardianApe, GreatShinobiOwl and IsshinTheSwordSaint, so the compiler creates 3 instances.

0 because there is no class or structure named Boss

A template is instantiated separately for each different type with which it is used. fight is called with 3 types: GuardianApe, GreatShinobiOwl and IsshinTheSwordSaint, so the compiler creates 3 instances.