(1)比较好理解的
1 class Fu { 2 int num1 = 5; 3 } 4 5 class Zi extends Fu { 6 int num2 = 4; 7 } 8 9 public class zihefu { 10 11 public static void main(String[] args) { 12 Zi z = new Zi(); 13 System.out.println(z.num1 + "....." + z.num2); 14 15 } 16 17 }
(2)比较能理解的
1 class Fu { 2 int num = 5; 3 } 4 5 class Zi extends Fu { 6 int num = 4; 7 } 8 9 public class zihefu { 10 11 public static void main(String[] args) { 12 Zi z = new Zi(); 13 System.out.println(z.num + "....." + z.num); 14 15 } 16 17 }
(3)this
1 class Fu { 2 int num = 5; 3 } 4 5 class Zi extends Fu { 6 int num = 4; 7 void show(){ 8 System.out.println(this.num);//注意看这,子类的方法 9 } 10 } 11 12 public class zihefu { 13 14 public static void main(String[] args) { 15 Zi z = new Zi(); 16 z.show(); 17 System.out.println(z.num + "....." + z.num); 18 19 } 20 }
(4)super
1 class Fu { 2 int num = 5; 3 } 4 5 class Zi extends Fu { 6 int num = 4; 7 void show(){ 8 System.out.println(super.num);//注意看这,子类的方法 9 } 10 } 11 12 public class zihefu { 13 14 public static void main(String[] args) { 15 Zi z = new Zi(); 16 z.show(); 17 System.out.println(z.num + "....." + z.num); 18 19 } 20 }