关于抽象类的理解问题:
abstract class aclass {
abstract void m1();
}
class aex1 extends aclass {
void m1() {System.out.println("aex1");}
}
class aex2 extends aclass {
void m1() {System.out.println("aex2");}
}
public class test {
void test(aclass a) {
a.m1();}
public static void main(String[] args) {
aclass a1 = new aex1();
aclass a2 = new aex2();
test(a1);
test(a2);
}
}
---------------------运行提示有错误如下:
non-static method test(aclass) cannot be referenced from a static context
test(a1);
non-static method test(aclass) cannot be referenced from a static context
test(a2);
问题出在哪里呢?
问题点数:20、回复次数:3Top
1 楼treeroot(旗鲁特)回复于 2005-06-03 10:01:18 得分 0
这个错误很低级,但是犯了也很正常
但是看到编译错误,还解决不了就不正常了Top
2 楼ftiger(哈哈鱼)回复于 2005-06-03 10:09:13 得分 20
non-static method 不能被 static 调用,就是说要先实例化。或将test 做成staticTop
3 楼zhenting(日,终于有offer了.)回复于 2005-06-04 08:54:32 得分 0
to treeroot(旗鲁特) : 积跬步而至千里,我想是每个人都必需经历的吧。
to ftiger(哈哈鱼):thanks。
Top




