Java多态之重写Overriding,先看一段代码:
package com.test; class A{ public void say(){ System.out.println("Hello ,A"); } } class B extends A{ public void say(){ System.out.println("Hello ,B"); } } class C extends B{ public void say(){ System.out.println("Hello ,c"); } } public class Demo02 { /** * @param args */ public static void main(String[] args) { A a = new A() ; a.say() ; System.out.println("-------------------------"); B b = new B() ; b.say() ; System.out.println("-------------------------"); C c = new C() ; c.say() ; } }
内存分析如下图: