物件的初始化過程

2021-07-05 07:39:03 字數 543 閱讀 2505

public class persond

persond (string name,int age)

public void setname(string name)

public void speak()

public static void showcountry()

/*persond p=new persond("張三",20);

* 該句話都做了什麼事情(沒涉及共享區)

* 1.因為new用到了persond.class,所以會會先找到persond.class並載入到記憶體中

* 2.執行該類中的static**塊,如果有的話,給persond.class類進行初始化

* 3.在堆記憶體中開闢空間,分配記憶體位址,

* 4.在堆記憶體中建立物件的特有屬性,並進行預設初始化

* 5.對屬性進行顯示初始化

* 6.對物件進行構造**塊初始化

* 7.對物件進行對應的建構函式初始化

* 8.將記憶體位址賦給棧記憶體中的p變數

* */

}

物件初始化過程

class person 靜態 塊 static 構造 塊 public void setname string name public void speak public static void showcountry class newperson 當程式執行到person p new pers...

物件初始化過程

1.這是個筆記.helloparent.class public class helloparent public helloparent hellochild.class public class hellochild extends helloparent public hellochild p...

java物件初始化過程

假設有一下類 class test test int n 0 我們知道,任何物件在使用前都會被初始化,方法裡面的區域性變數必須給初始化值才能通過編譯。現在我們來討論一下初始化的過程 對於字段 變數 而言,如果是基本型別,那麼即使不給初始值,都會得到jvm預設的初始值 boolean預設是false,...