Ruby program to implement single inheritance

bookmark

class SuperClass
    def initialize
        puts "SuperClass constructor";
    end

    def SayHello
        puts "Say hello from SuperClass";
    end
end

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

subObj = SubClass.new;
subObj.SayHello;

 


Output:

SubClass constructor
Say hello from SuperClass