1 package face_09; 2 class Fu { 3 Fu(){ 4 show(); 5 } 6 void show() { 7 System.out.println("hehe"); 8 } 9 } 10 class Zi extends Fu { 11 int num = 9; 12 Zi(){ 13 super(); 14 //显示初始化。 15 System.out.println("zi constructor"+ num); 16 } 17 void show() { 18 System.out.println("show.."+num); 19 } 20 } 21 public class Test { 22 public static void main(String[] args) { 23 new Zi(); 24 } 25 } 26 //打印show..0 27 //zi constructor9View Code
1 package face_09; 2 class Fu { 3 4 Fu(){ 5 System.out.println("fu constructor run"); 6 show(); 7 } 8 void show() { 9 System.out.println("hehe"); 10 } 11 } 12 class Zi extends Fu{ 13 int num = 8; 14 15 { 16 System.out.println("constructor code..."+num); 17 num = 10; 18 } 19 Zi(){ 20 super(); 21 //显示初始化 22 //构造代码块初始化 23 System.out.println("zi constructor..."+ num); 24 } 25 void show() { 26 System.out.println("show..."+num); 27 } 28 } 29 public class Test2 { 30 new Zi(); 31 }View Code
1 package face_09; 2 class Fu { 3 int num = 9; 4 { 5 System.out.println("Fu");//1 6 } 7 Fu(){ 8 super();//Object 9 //显示初始化。 10 //构造代码块初始化。 11 show(); 12 } 13 void show() { 14 System.out.println("fu show"+num); 15 } 16 } 17 class Zi extends Fu{ 18 int num = 8; 19 20 { 21 System.out.println("Zi");//3 Zi 22 } 23 Zi(){ 24 super(); 25 //显示初始化 26 //构造代码块初始化 27 show(); 28 } 29 void show() { 30 System.out.println("zi show"+num);//2 zi show 0 4, zi show 8 31 } 32 } 33 public class Test20 { 34 new Zi(); 35 }View Code