I just noticed something that I had never understood before. It turns out this class is valid in C #:
class Foo { private string contents; public Foo(string str) { contents = str; } public void set(Foo other) { contents = other.contents; } }
Thus, different instances of the same class can access each other's private members.
Until now, I thought that only this object can access private members of an object, and not other instances of the same class. It's a little surprising to find out.
Is this true in all ordinary object-oriented languages? This is not intuitive for me.
oop
Oliver
source share