大杂烩 -- 重载与覆写
基础大杂烩 -- 目录
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Class : A
package limeMianShi.duolaidian; public class A { public void whoAmI(){ System.out.println("I am A"); } }
Class : B
package limeMianShi.duolaidian; public class B extends A{ @Override public void whoAmI() { System.out.println("I am B"); } }
Class : Main
package limeMianShi.duolaidian; public class Test01 { public static void main(String[] args) { A a = new B(); test(a); } private static void test(A a) { System.out.println("this is A"); a.whoAmI(); } private static void test(B b){ System.out.println("this is B"); b.whoAmI(); } }
Console :
this is A I am B
啦啦啦