JVM

17-对象的实例化、内存分配与访问定位演示

2021-05-04  本文已影响0人  紫荆秋雪_文

一、对象的实例化

1.1、创建对象常用的方式

-1、最常用的方式

new Object()

1.2、创建对象的过程

二、对象的内存布局

2.1、对象头(Header)

2.2、实例数据(Instance Data)

2.3、对齐填充(Padding)

三、对象的访问定位

四、实例分析

4.1、code

package com.lkty.method;

public class Customer {
    int id = 10086;
    String  name;
    Account account;

    {
        name = "匿名客户";
    }

    public Customer() {
        this.account = new Account();
    }
}

class Account {

}

4.2、测试代码

package com.lkty.method;

public class CustomerTest {
    public static void main(String[] args) {
        Customer customer = new Customer();
    }
}
image.png
上一篇 下一篇

猜你喜欢

热点阅读