Bird
0
0

Which of the following is the correct syntax to override a method named display in a Ruby child class?

easy📝 Syntax Q3 of 15
Ruby - Inheritance
Which of the following is the correct syntax to override a method named display in a Ruby child class?
Adef display; puts 'Child display' end
Bdef display() puts 'Child display' end
Cdef display puts 'Child display'; end
Ddef display( puts 'Child display'; end
Step-by-Step Solution
Solution:
  1. Step 1: Check method definition syntax

    In Ruby, method definitions use def method_name; ... end syntax.
  2. Step 2: Identify correct syntax among options

    def display; puts 'Child display' end correctly uses def display; puts 'Child display' end with semicolon and end keyword.
  3. Final Answer:

    def display; puts 'Child display' end -> Option A
  4. Quick Check:

    Correct method syntax = def display; puts 'Child display' end [OK]
Quick Trick: Use def method_name; ... end for method override [OK]
Common Mistakes:
  • Missing end keyword
  • Incorrect semicolon placement
  • Using parentheses incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes