当前位置:网站首页>对象创建的流程分析
对象创建的流程分析
2022-07-27 00:02:00 【江北-科技】
对象创建的流程分析
引入构造器
先看一个案例
class Person // 类 Person
{
int age = 90;
String name;
Person(String n,int a) // 构造器
{
name = n; // 给属性赋值
age = a; // ...
}
}
Person p=new Person("小倩", 20);
在JVM内存中的存储分析
流程分析(顺序不能乱)
- 首先会在方法区中加载 Person 类信息( Person.class),只会加载这一次
- 进行 new Person(“小倩”,20) 在堆中分配空间(地址),创建对象
- 完成对象初始化
a. 默认初始化 age = 0 name = null
b.显式初始化 age = 90 name = null
c.构造器初始化 age = 20 name = 小倩 - 把对象在堆中的地址,返回给 P(P是对象名,也可以理解为对象的引用)
未引入构造器
加深理解回溯
代码
OK,本期分享就到这里,欢迎大家留言,感谢支持
边栏推荐
- Rust Web(一)—— 自建TCP Server
- I wish you a happy Chinese Valentine's day and invite you to read the source code together
- Is it necessary to open an account on site for securities speculation? Is it safe to open an account online
- ansible系列之:不收集主机信息 gather_facts: False
- 哪家券商开户买REITs基金比较安全?
- How small programs help the new model of smart home ecology
- After working in Tencent testing post for 5 years, I was ruthlessly dismissed in July, trying to wake up my brother who was still paddling
- 什么是进程?
- 系统安全测试要怎么做,详细来说说
- 消息队列学习 -- 概念
猜你喜欢

云开发寝适闹钟微信小程序源码

C language program compilation (preprocessing)

Static keyword

聊聊连接池和线程

解决小程序报错getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json

Rust Web(一)—— 自建TCP Server

Hcip OSPF interface network interface type experiment

白盒测试案例设计(我爷爷都能看懂)

Goatgui invites you to attend a machine learning seminar

消息队列学习 -- 概念
随机推荐
LeetCode->二分查找打卡(三)
Scheduling of processes
Okaleido Tiger 7.27日登录Binance NFT,首轮已获不俗成绩
The latest multi-threaded & highly concurrent learning materials, interview confidence
Hcip OSPF interface network interface type experiment
【无标题】
uni-app上自定义微信小程序的tabbar
"Software testing" packaging resume directly improves the pass rate from these points
C语言程序的编译上
Database read-write separation and database and table segmentation
[untitled]
Go language slow start -- go operator
Leetcode- > binary search clock in
消息队列学习 -- 概念
MySQL 5.7 takes the first item of the group
中断、信号、系统调用
BP plug-in temporary code record
After ten years of testing, I want to say to my friends who are still confused: one thing is to do a good job in personal planning
Talk about connection pools and threads
Knowledge points of test questions related to software testing