能否帮助我理解私有方法和受保护方法的区别.关于http://msdn.microsoft.com/en-us/library/ba0a1yw2%28v=VS.71%29.aspx 我无法理解它,特别是短语"Private:Access仅限于包含类型. "
谢谢你的帮助.再见!
class Test
{
private method myMethod()
{}
protected method myprotectedMethod()
{}
}
class ChildTest : Test
{
public method useProtectedBaseMethod ()
{
this.myProtectedMethod(); // this is ok
this.myMethod(); // this is NOT ok. will throw an Error
}
}
class outsider
{
Test objTest = new Test();
objTest.myProtectedMethod(); // throws an error as it is not accessible
objTest.myMethod(); // throws an error as it is not accessible
}
Run Code Online (Sandbox Code Playgroud)