Cannot use super in a static context //不能在静态上下文中使用super方法 //也不能用super调用static方法 package test;class Z { void f() { System.out.println("Hello!"); } }class test extends Z { void f() { System.out.println("Goodbye!"); super.f(); } public static void main(String[] args) { test bb = new test(); bb.f(); }}
//不能在静态上下文中使用super方法
//也不能用super调用static方法
package test;class Z {
void f() {
System.out.println("Hello!");
}
}class test extends Z {
void f() {
System.out.println("Goodbye!");
super.f();
} public static void main(String[] args) {
test bb = new test();
bb.f();
}}
这也太基础了吧.
super是父类对象,当然不能用在类方法中.super用法和this一模一样.
z.f();
编译类型和运行不一致,所以产生多态.当运行的时候, z才知道实际指向的是B类型,所以会调用子类中覆盖的方法.