Bird
0
0

Find the error in this Ruby code:

medium📝 Debug Q7 of 15
Ruby - Inheritance
Find the error in this Ruby code:
class Parent
  def display
    "Parent display"
  end
end

class Child < Parent
  def display
    super(1)
  end
end

puts Child.new.display
AChild's display method should not call super
BParent's display method does not accept arguments but super is called with one
Csuper must be called without arguments
DParent class must inherit from Child
Step-by-Step Solution
Solution:
  1. Step 1: Check parent method parameters

    Parent's display method takes no arguments.
  2. Step 2: Analyze super call in child

    Child calls super(1) passing one argument, which causes an argument error because parent method expects none.
  3. Final Answer:

    Parent's display method does not accept arguments but super is called with one -> Option B
  4. Quick Check:

    super argument mismatch causes error [OK]
Quick Trick: super arguments must match parent method parameters [OK]
Common Mistakes:
  • Assuming super can take any arguments
  • Ignoring parent method signature
  • Thinking inheritance direction matters here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes