Ruby program to implement multiple getter/setter methods using accessors
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 the multiple getters/setters method using accessors 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 for multiple instance variables using accessors. Then we created the object of the Sample class with initial values. After that, we used getter/setter methods to get/set the values of ins_var1, ins_var2 variables and print the result.
need an explanation for this answer? contact us directly to get an explanation for this answer