当前位置:网站首页>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
边栏推荐
- Some basic functions of enterprise projects are developed, and important things are saved to online first a
- If you open an account of Huatai Securities by stock speculation, is it safe to open an account online?
- 2022.07.03 (LC 6109 number of people who know secrets)
- P4408 [NOI2003] 逃学的小孩(树的直径)
- JS how to realize array to tree
- Introduction to ACM combination counting
- Is it safe to open and register new bonds? Is there any risk? Is it reliable?
- How to effectively monitor the DC column head cabinet
- Nine Qi single chip microcomputer ny8b062d single key control four LED States
- What is the difference between port mapping and port forwarding
猜你喜欢

《论文笔记》Multi-UAV Collaborative Monocular SLAM

How many triangles are there in the golden K-line diagram?

Fast analysis -- easy to use intranet security software

圖解網絡:什麼是網關負載均衡協議GLBP?

兩個數相互替換

abc 258 G - Triangle(bitset)

OpenHarmony资源管理详解

1189. Maximum number of "balloons"

图解网络:什么是网关负载均衡协议GLBP?

Continuous modification of business scenario functions
随机推荐
模板的进阶
P4408 [NOI2003] 逃学的小孩(树的直径)
[selenium automation] common notes
如何避免电弧产生?—— AAFD故障电弧探测器为您解决
企业公司项目开发好一部分基础功能,重要的事保存到线上第一a
Tester's algorithm interview question - find mode
Five papers recommended for the new development of convolutional neural network in deep learning
JS convert pseudo array to array
实战模拟│JWT 登录认证
Data on the number of functional divisions of national wetland parks in Qinghai Province, data on the distribution of wetlands and marshes across the country, and natural reserves in provinces, cities
TS快速入门-函数
lambda表达式
兩個數相互替換
他做国外LEAD,用了一年时间,把所有房贷都还清了
Huawei employs data management experts with an annual salary of 2million! The 100 billion market behind it deserves attention
[论文阅读] CarveMix: A Simple Data Augmentation Method for Brain Lesion Segmentation
Réseau graphique: Qu'est - ce que le Protocole d'équilibrage de charge de passerelle glbp?
2022.07.03(LC_6109_知道秘密的人数)
Netcore3.1 JSON web token Middleware
Date time type and format in MySQL