Bird
0
0

Consider this Ruby code snippet:

medium📝 Debug Q14 of 15
Ruby - Inheritance
Consider this Ruby code snippet:
class Fruit; end
class Apple < Fruit; end

puts Apple < fruit

What is the error and how to fix it?
ANo error; output is true
BSyntaxError: invalid syntax; fix by adding parentheses
CTypeError: wrong argument type; fix by using instance instead of class
DNameError: uninitialized constant 'fruit'; fix by capitalizing 'Fruit'
Step-by-Step Solution
Solution:
  1. Step 1: Identify the error

    The code uses lowercase 'fruit' instead of 'Fruit'. Ruby constants (classes) must start with uppercase letters. This causes a NameError.
  2. Step 2: Fix the error

    Change 'fruit' to 'Fruit' to reference the class correctly.
  3. Final Answer:

    NameError: uninitialized constant 'fruit'; fix by capitalizing 'Fruit' -> Option D
  4. Quick Check:

    Class names start uppercase [OK]
Quick Trick: Class names always start with uppercase letter [OK]
Common Mistakes:
  • Using lowercase for class names
  • Confusing variables with class constants
  • Trying to call < on instances instead of classes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes