Ruby program to implement getter and setter methods
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 getter and setter methods is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created a class Sample. The Sample class contains constructor, getter method GetVal(), and setter method SetVal(). We assigned the value of the instance variable using the constructor and SetVal() method. After that, we created the object of the Sample class and used the getter and setter method to get/set the value of the ins_var variable.
need an explanation for this answer? contact us directly to get an explanation for this answer