当前位置:网站首页>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
边栏推荐
- JS convert pseudo array to array
- Instructions for go defer
- leetcode494,474
- Specification for fs4061a boost 8.4v charging IC chip and fs4061b boost 12.6V charging IC chip datasheet
- Summary of week 22-07-02
- Verilog tutorial (11) initial block in Verilog
- What is the difference between port mapping and port forwarding
- [IELTS reading] Wang Xiwei reads P4 (matching2 paragraph information matching question [difficult])
- 2022.07.03(LC_6109_知道秘密的人数)
- It's too convenient. You can complete the code release and approval by nailing it!
猜你喜欢
URLs and URIs
青海省国家湿地公园功能区划数数据、全国湿地沼泽分布数据、全国省市县自然保护区
Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
电力运维云平台:开启电力系统“无人值班、少人值守”新模式
多回路仪表在基站“转改直”方面的应用
abc 258 G - Triangle(bitset)
ORB(Oriented FAST and Rotated BRIEF)
Deux nombres se remplacent
js如何实现数组转树
"Xiaodeng" domain password policy enhancer in operation and maintenance
随机推荐
Introduction to ACM combination counting
2022.07.03 (lc_6111_counts the number of ways to place houses)
【雅思阅读】王希伟阅读P4(matching2段落信息配对题【困难】)
人脸识别5- insight-face-paddle-代码实战笔记
电力运维云平台:开启电力系统“无人值班、少人值守”新模式
Skills in analyzing the trend chart of London Silver
雅思考试流程、需要具体注意些什么、怎么复习?
业务实现-日志写到同一个行数据里面
Nine Qi single chip microcomputer ny8b062d single key control four LED States
他做国外LEAD,用了一年时间,把所有房贷都还清了
企业应用业务场景,功能添加和修改C#源码
1189. Maximum number of "balloons"
Hisilicon 3559 universal platform construction: YUV422 pit stepping record
Basic points of the game setup of the points mall
How to save your code works quickly to better protect your labor achievements
ORB(Oriented FAST and Rotated BRIEF)
Distributed base theory
Two numbers replace each other
Go step on the pit - no required module provides package: go mod file not found in current directory or any parent
Face recognition 5- insight face padding code practice notes