Ruby program to initialize instance variables using the constructor
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 initialize instance variables using the constructor 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 the constructor and show() method. We initialized the instance variables ins_var1, ins_var2 in the constructor and printed them inside the show() class.
need an explanation for this answer? contact us directly to get an explanation for this answer