Bird
0
0

Identify the error in this Ruby code:

medium📝 Debug Q6 of 15
Ruby - Inheritance
Identify the error in this Ruby code:
class Base
  def info
    'Base info'
  end
end

class Derived < Base
  def info
    super()
    puts 'Derived info'
  end
end

Derived.new.info
ADerived class must not override info method.
Bsuper() cannot be called without arguments.
Csuper() is called but its return value is ignored.
Dputs cannot be used inside method overriding.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze super() call

    super() calls the parent method but its return value is not used or printed.
  2. Step 2: Effect of ignoring return value

    The parent's string is discarded; only 'Derived info' is printed.
  3. Final Answer:

    super() is called but its return value is ignored. -> Option C
  4. Quick Check:

    Ignoring super return value = super() is called but its return value is ignored. [OK]
Quick Trick: Use or return super's value to avoid ignoring it [OK]
Common Mistakes:
  • Thinking super() must have arguments
  • Believing puts is disallowed in overrides
  • Assuming overriding is forbidden

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes