Possible Duplicate:
Why can’t I access C# protected members except like this?
As I was reading a c# book (special annotated version which shows all the tricky part of c#)
I saw this code :
public class A
{
protected int x;
static void F(A a, B b)
{
a.x = 1; // Okay
b.x = 1; // Okay
}
}
public class B: A
{
static void F(A a, B b)
{
a.x = 1; // Error: must access through instance of B
b.x = 1; // Okay
}
}
looking at protected
meanning :
Access limited to this class or classes derived from this class
Questions
Why does this restriction (via instances) exists ?
Can you please supply an example of a problematic situation as if it was allowed ?