一、記憶體分析 代碼:引用可以是局部變數也可以是成員變數 二、對象之間建立關係 二、源碼: D34_husband_and_wife.java 地址: https://github.com/ruigege66/Java/blob/master/D34_husband_and_wife.java 2. ...
一、記憶體分析
代碼:引用可以是局部變數也可以是成員變數
public class Test1{ public static void main(String[] args){ User u = new User(); u.no = 40; u.name = "ajflasd "; u.address = new address(); //name、no都是引用,它們存儲的是堆記憶體中對應實例變數的地址 } }
二、對象之間建立關係
public class D34_husband_and_wife{ public static void main(String[] args){ Husband huangxiaoming = new Husband(); Wife baby = new Wife(); huangxiaoming.name = "huangxiaoming"; baby.name = "baby"; //上面的例子其實將兩個人割裂開來,沒有建立關係 //下麵對她們進行建立關係 huangxiaoming.w = baby; baby.h = huangxiaoming; } } class Wife { String name; Husband h; } class Husband { String name; Wife w; }
二、源碼:
D34_husband_and_wife.java
地址:
https://github.com/ruigege66/Java/blob/master/D34_husband_and_wife.java
2.CSDN:https://blog.csdn.net/weixin_44630050(心悅君兮君不知-睿)
3.博客園:https://www.cnblogs.com/ruigege0000/
4.歡迎關註微信公眾號:傅里葉變換,個人公眾號,僅用於學習交流,後臺回覆”禮包“,獲取大數據學習資料