一些关于static modifier 的说明,我有点迷惑,请那位师兄给指点一下! 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 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 class X{ static m0(){} m1(){}}比方说,你可以用2种方法来使用m0: - X.m0(); - X x=new X(); x.m0();但对于m1来说就不同: - X x=new X(); x.m1(); static method 也叫類方法,它可以通過類名直接訪問,也可以通過實例變量來訪問.就像樓上朋友所說的.static method不能訪問非static變量.static method不能被override 但是可以被overload to楼上的:static method可以被override为static method,但不可以被override为non-static method原话见:java2认证考试指南(英文原版),第69页。 to:karma(无为),,hahaha88(忧郁的眼神,稀嘘的胡子喳)你们讲得我有一点明白了,可是对于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; } } java.io.EOFException 使用Eclipse 3.4 GANYMEDE 版本的问题 关于SWT的问题 如何提示文件中的内容 关于文件处理API中的更改文件名的函数renameTo()问题!----Rename有时失败! 一个动态绑定问题,请教知情者 稀奇问题 ,小弟跪拜请教,谢谢!急急急! 如何运行JBUILDER编译的程序 “[Microsoft][ODBC 驱动程序 管理器] 非法的描述器索引”是怎么回事儿?谢谢 送分0 初学JAVE需要安装什么软件? SCJP中要考到Collection Classes吗?具体范围?怎么考?
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;
}
}