日期:2014-05-20 浏览次数:20905 次
class A{ public static int x = -1; A(){ System.out.println("AAA"); System.out.println(x); System.out.println(getX()); } public int getX(){ return x; } } class B extends A{ B(int x){ System.out.println("BBB"); x = x + 4; System.out.println(x); System.out.println(getX()); } public int getX(){ return x + 1; } } public class ReTest{ public static void main(String args[]){ B b = new B(0); System.out.println(b.getX()); } }
class A{ public static int x = -1; public A(){ System.out.println("AAA"); System.out.println(x); System.out.println(this.getX()); } public int getX(){ System.out.println("super class x:"+x); return x; } } class B extends A{ public B(int x){ System.out.println("BBB"); x = x + 4; System.out.println(x); System.out.println(getX()); } public int getX(){ System.out.println("extend class x:"+x); return x + 1; } } public class ReTest{ public static void main(String args[]){ B b = new B(0); System.out.println(b.getX()); } }