我有困惑與下面的代碼:在這個程序的靜態上下文中如何訪問非靜態的?
class A
{
int x;
static void F(B b) {
b.x = 1; /* Ok,
I want to know how is this ok, in a static block how a non static
instance variables are called because as I know that static block
gets memory at compile time before execution of a single command
while non static at run time and static method accessing a non static
variable which is not created yet please elaborate me on this
*/
}
}
class B: A
{
static void F(B b) {
b.x = 1; // Error, x not accessible
}
}
您的意思是public int x? – 2010-11-15 07:48:41
沒有公共int x。 – NoviceToDotNet 2010-11-15 09:12:06