父类如下
package test.ExtendsDemo; public class FuTest { public void method(){ System.out.println("父类的方法 is running ...."); } }
子类如下:
package test.ExtendsDemo; public class ZiTest extends FuTest{ @Override public void method(){ System.out.println("子类的方法 is running ..."); } }
测试类如下:
package test.ExtendsDemo; public class test { public static void main(String[] args) { ZiTest z = new ZiTest(); z.method(); FuTest f = new FuTest(); f.method(); FuTest f_z = new ZiTest(); f_z.method(); } }
控制台输出如下