注册 登录
编程论坛 新人交流区

关于protected在子类中的问题

iamheyjudy 发布于 2007-11-03 13:47, 466 次点击

请教:
在子类中为什么不能引用父类中protected的变量
代码如下:
Class Myclass
{
proteced string prostring = "protecedstring";
}
Class Mainclass:Myclass
{
static void Main(string[] args)
{
Myclass test = new Myclass();
test.prostring;
}
}
问一下上面花横线的语句为什么不对?谢谢了!

3 回复
#2
洛伊2007-11-03 14:04
当然了
在C++中那是受限制的,你只能通过方法去把它调出来!
#3
Naruto19832007-11-03 14:15
怎么没有其他的答案???
#4
iamheyjudy2007-11-03 14:28
回复:(iamheyjudy)关于protected在子类中的问题
Class Myclass
{
proteced string prostring = "protecedstring";

//调用prostring方法
protected string Do()
{
return prostring;
}

}
Class Mainclass:Myclass
{
static void Main(string[] args)
{
Myclass test = new Myclass();
//test.prostring;

string getstring = test.Do();

}
}

首先谢谢指教,您说的是这个意思吗?
1