Bird
0
0

Which of the following is the correct syntax to define a method named hello that takes no arguments?

easy📝 Syntax Q3 of 15
Ruby - Methods
Which of the following is the correct syntax to define a method named hello that takes no arguments?
Adef hello() end
Bdef hello
Cdef hello[] end
Ddef hello{} end
Step-by-Step Solution
Solution:
  1. Step 1: Recall method syntax in Ruby

    Methods are defined with def method_name(arguments) and closed with end. Parentheses are optional if no arguments.
  2. Step 2: Check each option

    A: def hello is missing the end keyword (invalid). B: def hello() end is correct. C: def hello[] end and D: def hello{} end use invalid brackets.
  3. Final Answer:

    def hello() end -> Option A
  4. Quick Check:

    def method() ... end is correct syntax [OK]
Quick Trick: Use def name() ... end to define methods with no args [OK]
Common Mistakes:
MISTAKES
  • Using square brackets instead of parentheses
  • Using curly braces for method definition
  • Omitting end keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes