Ruby program to call a superclass constructor from sub-class using the super() method

bookmark

class SuperClass
    def initialize
        puts "SuperClass constructor";
    end
end

class SubClass < SuperClass
    def initialize
        super();
        puts "SubClass constructor";
    end
end

subObj = SubClass.new;

 


Output:

SuperClass constructor
SubClass constructor