zoukankan      html  css  js  c++  java
  • 对象创建在内存中的引用

    创建一个对象,他在堆内存中还是在栈内存中

    Person p =new Person(“张三”,20);
    这样的,我可不可以这样理解new Person(“张三”,20)在堆内存中创建,分配内存地址。
    Person p 在栈内存中创建,然后把堆内存中的内存地址付给栈内存中的p变量

                Common common = new Common { Name = "张三" };
    
                Service service = new Service(common);
    
                //都是 指向李四
                common.Name = "李四";
                //service.dao = new Dao(common);
                //还是 李四 unbelieveable
                common = null;
    
                common = new Common { Name = "王五" };
                Console.ReadLine();
    
      public class Common
        {
            public string Name { get; set; }
        }
    
        public class Service
        {
            public Common _com;
            public Dao dao;
            public Service(Common comm )
            {
                this._com = comm;
                this.dao = new Dao(comm);
            }
        }
    
        public class Dao
        {
            public Common _com;
            public Dao(Common comm)
            {
                this._com = comm;
            }
        }

    对应代码 自理解图

  • 相关阅读:
    接口测试01
    mysql主从
    linux下配置JDK
    linux常用命令
    mysql基本语句
    线程与进程
    loadrunner函数
    设计模式-模板方法模式
    设计原则-CRP合成复用原则
    设计原则-LOD迪米特法则
  • 原文地址:https://www.cnblogs.com/kunlunmountain/p/13659231.html
Copyright © 2011-2022 走看看