Possible duplicate:
Why are private types private to the type and not the instance?
Consider the following class:
public class Test
{
protected string name;
private DateTime dateTime;
public Test(string name)
{
this.name = name;
this.dateTime = DateTime.Now;
}
public Test(Test otherObject)
{
this.name = otherObject.name;
this.dateTime = otherObject.GetDateTime();
}
private DateTime GetDateTime()
{
return dateTime;
}
public override string ToString()
{
return name + ":" + dateTime.Ticks.ToString();
}
}
In my constructor, I call closed or protected material otherObject. Why is this possible? . I always thought that the private was really private (assuming that the object can call this method / variable) or protected (only accessible when overloaded).
Why and when will I have to use this feature?
Is there some kind of OO logic / principle that I am missing?
source
share