Bird
0
0

Why does Ruby prefer modules over multiple inheritance to share behavior between classes?

hard📝 Conceptual Q10 of 15
Ruby - Modules and Mixins
Why does Ruby prefer modules over multiple inheritance to share behavior between classes?
AModules are faster to execute than multiple inheritance.
BModules avoid the complexity and ambiguity of multiple inheritance by linearizing method lookup.
CModules prevent any method overriding, ensuring safety.
DModules automatically merge methods from multiple parents.
Step-by-Step Solution
Solution:
  1. Step 1: Understand multiple inheritance issues

    Multiple inheritance can cause ambiguity and complexity in method resolution.
  2. Step 2: Ruby's module approach

    Ruby uses modules to linearize method lookup, avoiding ambiguity and simplifying behavior sharing.
  3. Final Answer:

    Modules avoid the complexity and ambiguity of multiple inheritance by linearizing method lookup. -> Option B
  4. Quick Check:

    Ruby's preference for modules = A [OK]
Quick Trick: Modules linearize method lookup to avoid ambiguity [OK]
Common Mistakes:
  • Thinking modules are faster than inheritance
  • Believing modules prevent overriding
  • Assuming modules merge methods automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes