c# 2.0 - why a protectd method of a class can nor be accessed by creating its object in sub class? -


i have code this, giving error can not access protected member.

**class { protected void m1()        {         code        } } class b:a { b b=new b(); b.m1();// ok works fine a =new a(); a.m1();///   don't work, compile time error a2=new b(); a2.m1(); //compile time error, don't work }** 

just not getting reason behind this, why aberrant nature of above code, why method of class using same class object not accessible out side. while searched bit did not undersand, found compiler nature come in picture, did not understand.

you can prefix call base keyword calling base members. protected means member inherited descendants , called through specified way.

calling a.m1() in class hasn't difference calling form out of b code.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -