【发布时间】:2017-10-06 11:38:42
【问题描述】:
class Abc{
public static void hello(){
System.out.println("parent");//Line1
}
}
class Abc1 extends Abc{
public void hello(){//Line2
System.out.println("child");//Line3
}
}
编译器在第 3 行给出错误提示
此实例方法不能覆盖来自 Abc 的静态方法
为什么静态方法不能被实例方法覆盖?
【问题讨论】:
-
第二种方法需要一个ABC1类的对象实例。
-
因为覆盖只对多态实例方法有意义?
标签: java inheritance