I just noticed something that I've never realised before. It turns out that 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;
}
}
So different instances of the same class can access the private members of each other.
Up til now, I thought that the private members of an object could only be accessed by that object, not by other instances of the same class. It's a little suprising to find this out.
Is this the case in all common object oriented languages? It's not intuitive for me.