Originally posted by Rewa Dev:
Is it a bug or an expected behaviour.
It is definitely expected behavior. Some languages (
Java, C++, and others) have class-based encapsulation, in which the class is the level of protection. Others (Ruby is a good example) have object-based encapsulation, in which one object can't call the private members of another; this is rather rarer. Both have their advantages; note that writing comparison methods, clone methods, etc, can be difficult in object-based encapsulation systems.