Bird
0
0

Find the error in this Ruby code:

medium📝 Debug Q6 of 15
Ruby - Inheritance
Find the error in this Ruby code:
class Fruit; end
class Apple < Fruit; end
puts Apple < "Fruit"
ASyntax error in class declaration
BApple is not subclass of Fruit
CMissing end keyword for class
DCannot compare class with string using <
Step-by-Step Solution
Solution:
  1. Step 1: Identify types compared with <

    The < operator for subclass check expects two classes, not a string.
  2. Step 2: Analyze the code

    Apple < "Fruit" compares a class with a string, causing a TypeError.
  3. Final Answer:

    Cannot compare class with string using < -> Option D
  4. Quick Check:

    Subclass check requires class operands [OK]
Quick Trick: Both sides must be classes for < subclass check [OK]
Common Mistakes:
  • Using string instead of class name
  • Assuming string works like class
  • Ignoring type mismatch errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes