I've a class with a private member. In this class I create an instance of this class. And I'm quite surpised that I can access the private member through this instance.
Here is the example.
public class MyClass
{
private Object myPrivateMember;
public MyClass()
{
myPrivateMember = new Object();
}
public void createInstance()
{
MyClass instanceOfMyClass;
instanceOfMyClass = new MyClass();
// This is the surprising line because there is no problem
instanceOfMyClass.myPrivateMember = new Object();
}
}
I was thinking that, when a member is private, the only way to access it, is through a so-called set and get method. (These methods access to it via this.thePrivateMember).
Can someone explain me why this is allowed ???
Thanks in advance.
------------------
Laurent
Leonard Laurent.Leonard@advalvas.be