Complete the code to define a class that inherits from another class in Ruby.
class ChildClass < [1] def greet puts 'Hello from child' end end
<.<.The < symbol is used in Ruby to indicate inheritance. Here, ChildClass inherits from ParentClass.
Complete the code to call the parent class method from the child class in Ruby.
class Parent def greet puts 'Hello from parent' end end class Child < Parent def greet [1] puts 'Hello from child' end end
Parent.greet directly, which is incorrect syntax.self.greet which causes infinite recursion.In Ruby, super calls the same method from the parent class. Here, it calls greet from Parent.
Fix the error in the code to correctly inherit and override a method in Ruby.
class Animal def speak puts 'Animal sound' end end class Dog [1] Animal def speak puts 'Bark' end end
In Ruby, the < symbol is used to indicate inheritance from a parent class.
Fill both blanks to create a class that inherits from a parent and calls the parent's method in Ruby.
class Vehicle def start puts 'Vehicle started' end end class Car [1] Vehicle def start [2] puts 'Car started' end end
The class Car inherits from Vehicle using <. Inside start, super calls the parent's start method.
Fill all three blanks to define a parent class, a child class inheriting it, and call the parent's method in Ruby.
class [1] def info puts 'Parent info' end end class [2] < [3] def info super puts 'Child info' end end
super to invoke the parent's method.The Child class inherits from Parent. The info method in Child calls super to run the parent's info method first.