Bird
0
0

What will this Ruby code print?

medium📝 Predict Output Q5 of 15
Ruby - Inheritance
What will this Ruby code print?
module Flyable; end
class Bird
  include Flyable
end
bird = Bird.new
puts bird.kind_of?(Flyable)
Afalse
Bnil
Ctrue
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand module inclusion

    Bird includes Flyable, so Bird instances are considered kind_of? Flyable.
  2. Step 2: Evaluate kind_of? call

    bird.kind_of?(Flyable) returns true because modules included behave like ancestors.
  3. Final Answer:

    true -> Option C
  4. Quick Check:

    kind_of? returns true for included modules [OK]
Quick Trick: kind_of? returns true for included modules too [OK]
Common Mistakes:
  • Thinking modules are not checked by kind_of?
  • Expecting false for modules
  • Confusing include with inheritance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes