Câu hỏi phỏng vấn Ruby
Câu hỏi

Are instance methods public or private?

Câu trả lời

Instance methods are public by default. This means they can be accessed from outside the class unless their visibility is explicitly changed using access modifiers such as private or protected. In Ruby, for instance, you can change the visibility of instance methods using Module#private, Module#protected, or revert to public using Module#public[1]. Similarly, in Java, instance methods are also public by default unless specified otherwise[2].

Citations:
[1] https://github.com/nick-brown/ruby-interview-questio...

junior

junior

Gợi ý câu hỏi phỏng vấn

junior

Can you call a private method outside a Ruby class using its object?

middle

How is the invocation of a private method different than the invocation of a public method from within its
defining class?

middle

What is the difference between Module#remove_method and Module#undef_method ?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào