【发布时间】:2011-06-03 22:13:21
【问题描述】:
我有一个疑问......
1)我们可以从任何非静态方法调用和访问任何静态方法或变量,但从静态方法我们不能访问任何非静态方法或变量.....为什么。
2) 但我们可以从静态方法创建任何类的实例。
请告诉我更好地回答我的问题的原因。
class Class1
{
static int x=0;
int w = 0;
private static Class2 test()
{
w = 88; // give error because w is not a static member.
test1(); // give error because test1() is not a static function.
Class2 z = new Class2(); // here i am creating instance of class2
return z;
}
private int test1()
{
x = 9;
return x;
}
}
class Class2
{
}
谢谢
【问题讨论】: