Bird
0
0

Identify the problem in this Ruby code snippet:

medium📝 Debug Q7 of 15
Ruby - Inheritance
Identify the problem in this Ruby code snippet:
module M
  def hello
    'Hi'
  end
end

class A
  include M
end

class B < A
  include M
end
AClass B cannot inherit from A
BRedundant module inclusion in subclass
CSyntax error in module declaration
DModule M cannot be included twice
Step-by-Step Solution
Solution:
  1. Step 1: Understand module inclusion inheritance

    When a module is included in a parent class, subclasses inherit its methods automatically.
  2. Step 2: Identify redundancy

    Including the same module again in subclass is unnecessary but not an error.
  3. Final Answer:

    Redundant module inclusion in subclass -> Option B
  4. Quick Check:

    Module inclusion in subclass = Redundant but allowed [OK]
Quick Trick: Modules included in parent are inherited by subclasses [OK]
Common Mistakes:
  • Thinking including module twice causes error
  • Believing subclass cannot inherit from parent with modules
  • Confusing syntax errors with redundancy

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes