1 class SuperClass { 2 private int number; 3 4 5 public SuperClass() { 6 this.number = 0; 7 } 8 9 10 public SuperClass(int number) { 11 this.number = number; 12 } 13 14 15 public int getNumber() { 16 number++; 17 return number; 18 } 19 } 20 21 class SubClass1 extends SuperClass { 22 public SubClass1(int number) { 23 super(number); 24 } 25 26 } 27 28 class SubClass2 extends SuperClass { 29 private int number; 30 31 32 public SubClass2(int number) { 33 super(number); 34 } 35 36 } 37 38 public class SubClass3 extends SuperClass { 39 40 private int number; 41 42 43 public SubClass3(int number) { 44 super(number); 45 } 46 47 48 public int getNumber() { 49 number++; 50 return number; 51 } 52 53 54 public static void main(String[] args) { 55 SubClass3 a3 = new SubClass3(20); 56 SuperClass s = a3; 57 SubClass1 a1= new SubClass1(20); 58 SuperClass s1 = a1; 59 SubClass2 a2 = new SubClass2(20); 60 SuperClass s2 = a2; 61 System.out.println(s.getNumber()); 62 System.out.println(a3.getNumber()); 63 System.out.println(s1.getNumber()); 64 System.out.println(a1.getNumber()); 65 System.out.println(s2.getNumber()); 66 System.out.println(a2.getNumber()); 67 68 } 69 70 }
运行结果:
1
2
21
22
21
22
求解代码的运行思路?
不能回答,只能顶贴啦