代码如下:
class BaseTest
{
public int a = 10;
protected int b = 2;
}
class ChildTest:BaseTest
{
int c;
int d;
public void printTest()
{
BaseTest basetest = new BaseTest();
this.a=basetest.a;
this.c = basetest.b; //会报错
}
}
改成如下形式就正确了
class BaseTest
{
public int a = 10;
protected int b = 2;
}
class ChildTest : BaseTest
{
int c;
int d;
static void Main(string[] args)
{
ChildTest childTest = new ChildTest();
Console.WriteLine(childTest.b);
}
}