public class static_method {
public static void main(String[] args) {
Super2 sup2 = new Sub2();
/**
* output: class com.private_field_static_pitfall.test.Sub2
*/
System.out.println(sup2.getClass());
/**
* output: super2 f()静态方法不存在多态调用
*/
sup2.f();
}
}
class Super2 {
public static void f() {
System.out.println("super2 f()");
}
}
class Sub2 extends Super2 {
public static void f() {
System.out.println("sub2 f()");
}
/**
* error:This instance method cannot override the static method from Super2
protected void f() {
}
*/
}