Bird
0
0

What will this Ruby code print?

medium📝 Predict Output Q5 of 15
Ruby - Variables and Data Types
What will this Ruby code print?
def test
  _value = 20
  value = 10
  puts _value + value
end
test
A20
B30
C10
DError
Step-by-Step Solution
Solution:
  1. Step 1: Identify variable values

    _value is 20, value is 10 inside the method.
  2. Step 2: Calculate sum and output

    puts _value + value prints 20 + 10 = 30.
  3. Final Answer:

    30 -> Option B
  4. Quick Check:

    Sum of local variables = 30 [OK]
Quick Trick: Underscore variables are valid locals [OK]
Common Mistakes:
MISTAKES
  • Ignoring underscore prefix
  • Expecting error due to underscore

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes