4.9w+
社区成员
public class Father {
public void a_method {
System.out.println("我正在调用父类方法");
}
}
public class Sub extends Father {
}
public class Test {
public static void main(String [] args) {
Sub obj = new Sub();
obj.a_method();
}
}
public class Father {
public static void two_method {
System.out.println("父类静态方法2");
}
public static void three_method {
System.out.println("父类静态方法3");
}
}
public class Sub extends Father {
public static void three_method {
System.out.println("子类静态方法3");
}
}
public class Test {
public static void main(String [] args) {
Sub.two_method(); //正规的静态方法(类方法)调用规范
Sub obj = new Sub();
obj.two_method(); //不正规的静态方法(类方法)调用规范,Java不会报错,在一些语言中会报错
}
}
public class Test {
public static void main(String [] args) {
Sub obj = new Sub();
Father father = new Sub();
obj.three_method(); //输出结果:实际调用了Sub中定义的方法
father.three_method(); //输出结果:实际调用了Father中定义的方法
}
}