i have a code like this, but giving error can not access protected member.
**Class A
{
protected void m1()
{
some code
}
}
Class B:A
{
B b=new B();
b.m1();// Ok works fine
A a =new a();
a.m1();/// don't work, compile time error
A a2=new B();
a2.m1(); //compile time error, don't work
}**
just not getting reason behind this, Why so aberrant nature of the above code, why a method of a class using same class object not accessible out side. While i searched a bit for this but did not undersand, i found something that compiler nature come in picture, but i did not understand.
you can prefix your call by
basekeyword for calling base members.protectedmeans that a member could be inherited by descendants and could be called but through the specified way.calling
a.m1()in your class hasn’t any difference with calling it form an out of B code.