Examveda

Which of the following statements best describes the purpose of the attr_accessor method in Ruby classes?

A. It defines only a reader method for class attributes

B. It defines only a writer method for class attributes

C. It defines constructor methods for class attributes

D. It defines both reader and writer methods for class attributes

Answer: Option D


Join The Discussion

Related Questions on Inheritance and Polymorphism in Ruby

What is polymorphism in OOP?

A. The ability to hide implementation details

B. The ability to restrict access to certain methods

C. The ability for objects of different classes to be treated as objects of a common superclass

D. The ability to create multiple instances