※ 引述《kdok123 (小天)》之铭言:
: ex:
: class A{
: static void tell(){
: sout("I am A");
: }
: }
: class B extends A{
: static void tell(){
: super.tell(); //问题
: }
: }
: 问题:
: 有别于c++, Java的static是在runtime执行的
: 这样我想static的运算应该会少了很多限制
: 所以我测试了一下让static call super指针(两个都是runtime才运算的)
: 结果发现不行?
: 其实static用起来还是跟C++一样(至少我这么觉得...)
: 请问既然static是在runtime运行的,那为什么很多runtime的动作没办法一起做呢?
http://www.quora.com/Why-cant-static-method-access-this-or-super-in-Java
这个人解释得较好。
Ranjith Kumar S, Computer Engineer
A static method which belongs to the class and not to the object(instance).
It can access only static data. It can not access non-static data (instance
variables). It can be accessed directly by the class name and doesn’t need
any object.
this keyword can be used to refer current class instance variable.
http://www.javatpoint.com/this-k...
super is used to refer immediate parent class instance variable.
http://www.javatpoint.com/super-...
Eventually both this and super keyword refers to instance variables. So a
static method cannot refer to “this” or “super” keywords.