I have been told that, a protected variable in the base class can be accessed in the derived class either using base
or this
keyword. I am totally confused now, because, this
keyword refers to the current class (derived class).
public class A
{
protected int i;
}
public class B :A
{
void Display()
{
this.i=10;
// (or)
base.i=10;
}
}
Is there any technical difference ? First of all, today I am pondered to see why I cannot create an object of A inside Display()
method and access the variable i through that object as the very definition of protected access says that, it can be accessed in any derived class. Folks, I have seen some threads, however what they say is, we cannot create object and access the protected members. I feel, this is pretty contrary to the definition.
Could someone can please explain me both of my above questions