super關鍵字:
在java中使用super來引用基類的成分。
程式code:
class FatherClass{ public int value; public void f(){ value = 100; System.out.println("FatherClass.value:"+value); } } class ChildClass extends FatherClass{ private int value; public void f(){ super.f(); value=200; System.out.println("ChildClass.value:"+value); System.out.println(value); System.out.println(super.value); } } public class TestInHerit{ public static void main(String args[]){ ChildClass cc = new ChildClass(); cc.f(); } }
輸出結果:
記憶體分佈: