Bird
0
0

Identify the error in this Ruby code snippet:

medium📝 Debug Q6 of 15
Ruby - Inheritance
Identify the error in this Ruby code snippet:
class Animal; end
class Dog < Animal; end
obj = Dog.new
puts obj.is_a(Animal)
ANo error, code runs fine
BMissing question mark in is_a? method call
Cobj is not an instance of Dog
DDog class does not inherit from Animal
Step-by-Step Solution
Solution:
  1. Step 1: Check method syntax

    The method is_a? requires a question mark at the end.
  2. Step 2: Identify the error

    The code uses is_a without the question mark, causing a NoMethodError.
  3. Final Answer:

    Missing question mark in is_a? method call -> Option B
  4. Quick Check:

    Method is_a? needs question mark [OK]
Quick Trick: Remember is_a? ends with a question mark [OK]
Common Mistakes:
  • Omitting question mark in is_a?
  • Confusing is_a with is_a?
  • Assuming no error without question mark

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes