Bird
0
0

Which of the following is the correct way to declare a class inheriting from another class in Ruby?

easy📝 Syntax Q12 of 15
Ruby - Inheritance
Which of the following is the correct way to declare a class inheriting from another class in Ruby?
Aclass ChildClass : ParentClass; end
Bclass ChildClass inherits ParentClass; end
Cclass ChildClass extends ParentClass; end
Dclass ChildClass < ParentClass; end
Step-by-Step Solution
Solution:
  1. Step 1: Recall Ruby class inheritance syntax

    In Ruby, inheritance is declared using the less-than symbol (<) between class names.
  2. Step 2: Match syntax with options

    Only class ChildClass < ParentClass; end uses the correct Ruby syntax: class ChildClass < ParentClass; end.
  3. Final Answer:

    class ChildClass < ParentClass; end -> Option D
  4. Quick Check:

    Ruby inheritance uses < symbol = C [OK]
Quick Trick: Use < symbol to inherit a class in Ruby [OK]
Common Mistakes:
  • Using 'inherits' keyword which Ruby does not have
  • Using ':' or 'extends' like other languages
  • Forgetting the < symbol for inheritance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes