LearnFrenzy
Sign in Take a free test

Polymorphism and Virtual Functions · Polymorphism MCQ · Question 16

Why does passing by value break polymorphism? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 16 Back to Exercise

Why does void show(Animal a) { a.speak(); } always call Animal::speak, even for a Dog?

  • A speak is not public
  • B The Dog is copied into an Animal object (sliced), so the parameter really is an Animal Correct
  • C Virtual functions do not work in functions
  • D Animal must be abstract
Correct Answer: Option B

Take const Animal& (or a pointer) to keep the dynamic type.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links