Ruby program to implement getter/setter method using \'attr_accessor\' accessor
belongs to collection: Ruby Constructors/Destructors, Inheritance Programs
All Answers
total answers (1)
belongs to collection: Ruby Constructors/Destructors, Inheritance Programs
total answers (1)
Program/Source Code:
The source code to implement setter using "attr_accessor" accessor is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created a class Sample. In the Sample class, we implemented constructor and getter, setter methods using attr_accessor accessor. Then we created the object of the Sample class with the initial value. After that, we used getter/setter methods to get/set the value of the ins_var variable and print the result.
need an explanation for this answer? contact us directly to get an explanation for this answer