Bird
0
0

In Ruby, what does the expression ChildClass < ParentClass check?

easy📝 Conceptual Q11 of 15
Ruby - Inheritance
In Ruby, what does the expression ChildClass < ParentClass check?
AIf ChildClass and ParentClass are the same class
BIf ChildClass is an instance of ParentClass
CIf ChildClass is a subclass of ParentClass
DIf ParentClass is a subclass of ChildClass
Step-by-Step Solution
Solution:
  1. Step 1: Understand the < operator for classes

    In Ruby, the < operator between classes checks inheritance, specifically if the left class is a subclass of the right class.
  2. Step 2: Apply to ChildClass < ParentClass

    This expression returns true if ChildClass inherits from ParentClass, meaning ChildClass is a subclass.
  3. Final Answer:

    If ChildClass is a subclass of ParentClass -> Option C
  4. Quick Check:

    Subclass check = true if inheritance [OK]
Quick Trick: Remember: < means 'is subclass of' in Ruby classes [OK]
Common Mistakes:
  • Confusing subclass check with instance check
  • Thinking < checks equality of classes
  • Reversing the order of classes in the expression

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes