Bird
0
0

Which Ruby expression correctly checks if Cat is a subclass of Animal?

easy📝 Conceptual Q2 of 15
Ruby - Inheritance
Which Ruby expression correctly checks if Cat is a subclass of Animal?
ACat <= Animal
BAnimal < Cat
CCat > Animal
DCat < Animal
Step-by-Step Solution
Solution:
  1. Step 1: Recall subclass check syntax

    In Ruby, Child < Parent returns true if Child is subclass of Parent.
  2. Step 2: Apply to Cat and Animal

    Since Cat inherits from Animal, Cat < Animal is correct.
  3. Final Answer:

    Cat < Animal -> Option D
  4. Quick Check:

    Subclass check = Child < Parent [OK]
Quick Trick: Subclass check uses < with child on left [OK]
Common Mistakes:
  • Reversing the order of classes
  • Using > instead of <
  • Using <= which is invalid for classes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes