A normal method in a class has a hidden parameter, "this", which identifies which instance the method will operate on. But a static method does not have this hidden parameter, so it can only operate on static members
调试欢乐多
static m0(){}
m1(){}
}比方说,你可以用2种方法来使用m0:
- X.m0();
- X x=new X(); x.m0();但对于m1来说就不同:
- X x=new X(); x.m1();
static method不能訪問非static變量.
static method不能被override 但是可以被overload
static method可以被override为static method,但不可以被override为non-static method原话见:java2认证考试指南(英文原版),第69页。
你们讲得我有一点明白了,
可是对于this.还是有点困难,
static method and non-static method 有没有this有什么区别?
我写了这样一段程序,在是否使用static时出现错误,
non-static method cannot be refrenced from a static context
是不是只有这一点区别呢?class Hello{
int x;
static void xxx(){
int i=9;
x=10;
}
void yyy(){
int y;
y=x;
}
}