TestInherit.java
class="java" name="code">//super关键字 class FatherClass { public int value; public void f(){ value = 100; System.out.println ("FatherClass.value="+value); } } class ChildClass extends FatherClass { public int value; public void f() { super.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(); } }
?
F:\java>javac TestInherit.java F:\java>java TestInherit FatherClass.value=100 ChildClass.value=200 200 100 F:\java>
?内存分析:
?