Examveda

What is the difference between attr_reader, attr_writer, and attr_accessor in Ruby?

A. attr_reader defines both reader and writer methods, attr_writer defines only reader methods, and attr_accessor defines only writer methods

B. attr_reader defines both reader and writer methods, attr_writer defines only writer methods, and attr_accessor defines only reader methods

C. attr_reader defines only writer methods, attr_writer defines both reader and writer methods, and attr_accessor defines only reader methods

D. attr_reader defines only reader methods, attr_writer defines only writer methods, and attr_accessor defines both

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