Bird
0
0

What is wrong with this code?

medium📝 Debug Q7 of 15
Ruby - Advanced Metaprogramming
What is wrong with this code?
class Base
  def self.inherited
    puts "Subclass created"
  end
end

class Derived < Base; end
ASyntax error in class inheritance
BCannot define <code>inherited</code> in Base class
CMissing subclass parameter in <code>inherited</code> method
DNo error, code runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Check inherited method signature

    The inherited hook must accept one argument: the subclass.
  2. Step 2: Identify missing parameter

    Here, inherited is defined without parameters, so it will cause an error or unexpected behavior.
  3. Final Answer:

    Missing subclass parameter in inherited method -> Option C
  4. Quick Check:

    inherited needs subclass argument [OK]
Quick Trick: Always include subclass parameter in inherited method [OK]
Common Mistakes:
  • Omitting subclass parameter
  • Assuming no parameters needed
  • Confusing with other hooks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes