当前位置:网站首页>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
边栏推荐
- P3304 [SDOI2013]直径(树的直径)
- 业务实现-日志写到同一个行数据里面
- 22-07-02周总结
- abc 258 G - Triangle(bitset)
- Summer challenge brings you to play harmoniyos multi terminal piano performance
- [paper reading] cavemix: a simple data augmentation method for brain vision segmentation
- Two numbers replace each other
- P4408 [NOI2003] 逃学的小孩(树的直径)
- [论文阅读] CarveMix: A Simple Data Augmentation Method for Brain Lesion Segmentation
- 巩固表达式C# 案例简单变量运算
猜你喜欢

Specification for fs4061a boost 8.4v charging IC chip and fs4061b boost 12.6V charging IC chip datasheet

IELTS examination process, what to pay attention to and how to review?
![P3304 [sdoi2013] diameter (diameter of tree)](/img/5c/984675bf4517481f80f54657c6c7ad.png)
P3304 [sdoi2013] diameter (diameter of tree)

Learn C language from scratch day 024

lambda expressions

What did I pay for it transfer to testing post from confusion to firmness?

Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system

【雅思阅读】王希伟阅读P4(matching2段落信息配对题【困难】)

Consolidated expression C case simple variable operation

Learning of basic amplification circuit
随机推荐
Robot reinforcement learning synergies between pushing and grassing with self supervised DRL (2018)
2022.07.03 (lc_6111_counts the number of ways to place houses)
打新债开户注册安全吗?有没有风险的?靠谱吗?
Face recognition 5- insight face padding code practice notes
Acwing164. Accessibility Statistics (topological sorting +bitset)
Build your own minecraft server with fast parsing
【C】 (written examination questions) pointer and array, pointer
GDB common commands
初识ROS
Life is changeable, and the large intestine covers the small intestine. This time, I can really go home to see my daughter-in-law...
(脚本)一键部署redis任意版本 —— 筑梦之路
The waterfall flow layout demo2 (method 2) used by the uniapp wechat applet (copy and paste can be used without other processing)
如何有效对直流列头柜进行监测
挖财学院开户安全的吗?开户怎么开?
Distributed base theory
2022.07.03(LC_6111_统计放置房子的方式数)
实战模拟│JWT 登录认证
他做国外LEAD,用了一年时间,把所有房贷都还清了
基于三维gis平台的消防系统运用
[path planning] RRT adds dynamic model for trajectory planning