当前位置:网站首页>Parameter passing mechanism of member methods
Parameter passing mechanism of member methods
2022-07-05 00:26:00 【The learning path of Java Rookies】
Parameter transfer mechanism of basic data type
The basic data type passes a value , The change of formal parameter value will not lead to the change of actual parameter value
public class MethodParameter01 {
// Write a main Method
public static void main(String[] args) {
int a = 10;
int b = 20;
// establish AA object name obj
AA obj = new AA();
obj.swap(a, b); // call swap
System.out.println("main Method a=" + a + " b=" + b);//a=10 b=20
}
}
class AA {
public void swap(int a,int b){
System.out.println("\na and b Value before exchange \na=" + a + "\tb=" + b);//a=10 b=20
// It's done a and b In exchange for
int tmp = a;
a = b;
b = tmp;
System.out.println("\na and b Value after exchange \na=" + a + "\tb=" + b);//a=20 b=10
}
}
Here is my memory analysis of the above code
When swap After method execution , It's out of the stack , Memory free , And then go ahead and do it main Method ,swap Formal parameters in method a,b Changes that occur do not affect changes in arguments
The parameter passing mechanism of reference data type
Memory resolution
summary
When parameters are passed , The basic data type is a value , Parameter changes do not affect argument changes
The reference data type passes the memory address , The change of formal parameters will affect the change of arguments
边栏推荐
- Using fast parsing intranet penetration to realize zero cost self built website
- P3304 [sdoi2013] diameter (diameter of tree)
- Learn C language from scratch day 024
- [IELTS reading] Wang Xiwei reading P3 (heading)
- 人脸识别5- insight-face-paddle-代码实战笔记
- [论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
- The pit of sizeof operator in C language
- [Peking University] tensorflow2.0-1-opening
- "Xiaodeng" domain password policy enhancer in operation and maintenance
- Go step on the pit - no required module provides package: go mod file not found in current directory or any parent
猜你喜欢
[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
他做国外LEAD,用了一年时间,把所有房贷都还清了
如何有效对直流列头柜进行监测
Netcore3.1 JSON web token Middleware
Learning of basic amplification circuit
Verilog tutorial (11) initial block in Verilog
JS how to realize array to tree
[selenium automation] common notes
【雅思阅读】王希伟阅读P4(matching2段落信息配对题【困难】)
Oracle case: SMON rollback exception causes instance crash
随机推荐
abc 258 G - Triangle(bitset)
初识ROS
(脚本)一键部署redis任意版本 —— 筑梦之路
Ap8022 switching power supply small household appliances ACDC chip offline switching power supply IC
Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system
[论文阅读] CarveMix: A Simple Data Augmentation Method for Brain Lesion Segmentation
两个数相互替换
如何避免电弧产生?—— AAFD故障电弧探测器为您解决
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
P3304 [SDOI2013]直径(树的直径)
IT转测试岗,从迷茫到坚定我究竟付出了什么?
[Peking University] tensorflow2.0-1-opening
Get to know ROS for the first time
[selenium automation] common notes
雅思考试流程、需要具体注意些什么、怎么复习?
Multilingual Wikipedia website source code development part II
URLs and URIs
[monitoring] ZABBIX
Using the uniapp rich text editor
Basic points of the game setup of the points mall