Bird
0
0

In Ruby, how can a child class call the original method from its parent class after overriding it?

easy📝 Conceptual Q2 of 15
Ruby - Inheritance
In Ruby, how can a child class call the original method from its parent class after overriding it?
ABy using the keyword <code>super</code> inside the overridden method.
BBy calling <code>parent.method_name</code> directly.
CBy redefining the method again in the child class.
DBy using <code>this.parent_method</code>.
Step-by-Step Solution
Solution:
  1. Step 1: Identify how to access parent method

    Ruby uses the keyword super inside an overridden method to call the parent's version.
  2. Step 2: Understand usage of super

    When super is called, it runs the parent method with the same name.
  3. Final Answer:

    By using the keyword super inside the overridden method. -> Option A
  4. Quick Check:

    Call parent method with super = By using the keyword super inside the overridden method. [OK]
Quick Trick: Use super to call parent method inside override [OK]
Common Mistakes:
  • Trying to call parent method directly by name
  • Using incorrect keywords like this.parent_method
  • Redefining method again instead of calling super

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes