Ruby - InheritanceWhat happens when a child class overrides a method from its parent class in Ruby?ABoth parent and child methods run automatically in sequence.BThe parent class method is called instead of the child's method.CRuby throws an error because methods cannot be overridden.DThe child class provides its own version of the method, replacing the parent's version.Check Answer
Step-by-Step SolutionSolution:Step 1: Understand method overriding conceptIn Ruby, when a child class defines a method with the same name as in its parent, it replaces the parent's method.Step 2: Effect of overriding in child classCalling the method on a child class instance uses the child's version, not the parent's.Final Answer:The child class provides its own version of the method, replacing the parent's version. -> Option DQuick Check:Method overriding = Child method replaces parent method [OK]Quick Trick: Child method replaces parent method with same name [OK]Common Mistakes:Thinking both methods run automaticallyBelieving parent method always runsAssuming overriding causes errors
Master "Inheritance" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Class Methods and Variables - Frozen objects - Quiz 13medium Class Methods and Variables - Class variables (@@) and their dangers - Quiz 14medium Enumerable and Collection Processing - Zip for combining arrays - Quiz 5medium Enumerable and Collection Processing - Sort_by for custom sorting - Quiz 1easy Enumerable and Collection Processing - Each for iteration - Quiz 8hard Enumerable and Collection Processing - Sort_by for custom sorting - Quiz 14medium Error Handling - Why error handling uses rescue - Quiz 11easy Error Handling - Retry for reattempting - Quiz 6medium File IO - Dir operations for directories - Quiz 1easy Inheritance - Method lookup chain - Quiz 1easy