Bird
0
0

Why does Ruby allow variables to change type during execution without errors?

hard📝 Conceptual Q10 of 15
Ruby - Variables and Data Types
Why does Ruby allow variables to change type during execution without errors?
ABecause Ruby requires explicit type declarations for variables.
BBecause Ruby compiles all types before running the program.
CBecause Ruby restricts variables to one type only.
DBecause Ruby uses dynamic typing, checking types at runtime.
Step-by-Step Solution
Solution:
  1. Step 1: Recall Ruby's typing system

    Ruby is dynamically typed, meaning type checks happen while the program runs.
  2. Step 2: Understand effect on variables

    This allows variables to hold different types at different times without compile-time errors.
  3. Final Answer:

    Because Ruby uses dynamic typing, checking types at runtime. -> Option D
  4. Quick Check:

    Dynamic typing means runtime type checks [OK]
Quick Trick: Dynamic typing means runtime type flexibility [OK]
Common Mistakes:
  • Confusing dynamic typing with static typing
  • Thinking Ruby compiles types before running
  • Assuming variables have fixed types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes