namespace hi
{
class hithere
{
public int numberOne = 12;
public int numberTwo = 12;
static void yo()
{
public int numberThree = 12;
private int numberFour = 12;
}
}
}谁能告诉我这段代码中的变量numberOne,numberTwo,numberThree和numberFour之间的区别?
发布于 2010-12-14 23:56:57
numberOne和numberTwo是堆中的公共实例变量。它们可以在拥有hithere对象实例的对象中直接访问。不能以这种方式访问numberThree和numberFour,因为它们不是实例变量,并且被封装在函数yo的范围内并存储在其各自的堆栈中。
发布于 2010-12-14 23:52:35
numberOne和numberTwo是该类的成员变量。numberThree和numberFour是局部变量,作用域为函数。
接下来,您不能为局部变量声明访问修饰符(private / public)。
https://stackoverflow.com/questions/4441030
复制相似问题