Bird
0
0

Which of the following is the correct way to declare a class named Car in Ruby?

easy📝 Syntax Q3 of 15
Ruby - Classes and Objects
Which of the following is the correct way to declare a class named Car in Ruby?
Amodule Car; end
Bclass Car; end
Cdef Car; end
DCar class; end
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct class declaration syntax

    Ruby classes start with class ClassName and end with end.
  2. Step 2: Check other options for errors

    def is for methods, module defines modules, and Car class is invalid syntax.
  3. Final Answer:

    class Car; end -> Option B
  4. Quick Check:

    Class declaration = class Name; end [OK]
Quick Trick: Start class with 'class ClassName' and end with 'end' [OK]
Common Mistakes:
  • Using 'def' instead of 'class'
  • Confusing modules with classes
  • Incorrect order of keywords

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes