日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

动手动脑(三)

發布時間:2025/7/14 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 动手动脑(三) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原因:下面自己寫的構造方法帶有1個參數,但是在新建對象的時候卻沒有參數,所以無法進行初始化。

二,

1 package 統計對象個數; 2 3 public class InitializeBlockClass { 4 { 5 field=200; 6 } 7 public int field=100; 8 public InitializeBlockClass(int value) { 9 this.field=value; 10 } 11 public InitializeBlockClass() { 12 } 13 public static void main(String[] args) { 14 InitializeBlockClass obj=new InitializeBlockClass(); 15 System.out.println(obj.field); 16 obj=new InitializeBlockClass(); 17 System.out.println(obj.field); 18 } 19 }

運行截圖:

?

?

三,

1 class Root 2 { 3 static{ 4 System.out.println("Root的靜態初始化塊"); 5 } 6 { 7 System.out.println("Root的普通初始化塊"); 8 } 9 public Root() 10 { 11 System.out.println("Root的無參數的構造器"); 12 } 13 } 14 class Mid extends Root 15 { 16 static{ 17 System.out.println("Mid的靜態初始化塊"); 18 } 19 { 20 System.out.println("Mid的普通初始化塊"); 21 } 22 public Mid() 23 { 24 System.out.println("Mid的無參數的構造器"); 25 } 26 public Mid(String msg) 27 { 28 //通過this調用同一類中重載的構造器 29 this(); 30 System.out.println("Mid的帶參數構造器,其參數值:" + msg); 31 } 32 } 33 class Leaf extends Mid 34 { 35 static{ 36 System.out.println("Leaf的靜態初始化塊"); 37 } 38 { 39 System.out.println("Leaf的普通初始化塊"); 40 } 41 public Leaf() 42 { 43 //通過super調用父類中有一個字符串參數的構造器 44 super("Java初始化順序演示"); 45 System.out.println("執行Leaf的構造器"); 46 } 47 48 } 49 50 public class TestStaticInitializeBlock 51 { 52 public static void main(String[] args) 53 { 54 new Leaf(); 55 56 57 } 58 }

運行截圖:

?

轉載于:https://www.cnblogs.com/mawangwang/p/9826014.html

總結

以上是生活随笔為你收集整理的动手动脑(三)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。