Why does ruby allow child classes access parent’s private methods?

class Main
    def say_hello
        puts "Hello"
    end

    private
        def say_hi
            puts "hi"
        end
end

class SubMain < Main
    def say_hello
        puts "Testing #{say_hi}"
    end

end

test = SubMain.new
test.say_hello()    

OUTPUT:

hi

Testing


Source: oop

Leave a Reply