当前位置:网站首页>About local variables
About local variables
2022-07-29 05:33:00 【Xiao Hong is working hard】
About local variables ( Fallible )
stay java Only the value is passed in the call , No address call .
Look at a case directly :
- A() Methods will a Variables are added every time they are called 1;
- B() Methods will b Variables from lowercase b Put it in capital letters B;
- C() Methods will c[0] from "c" Change to "C";
public class Test3 {
@Test
public void test() {
int a = 0;
char b = 'b';
char[] c = {
'c'};
A(a);
B(b);
C(c);
System.out.println("a Variable final :" + a);
System.out.println("--------------------------------------------------------");
System.out.println("b Variable final :" + b);
System.out.println("--------------------------------------------------------");
System.out.println("c[0] Variable final :" + c[0]);
}
public void A(int a){
if(a != 2){
System.out.println(" Local a:" + a);
a += 1;
A(a);
}
}
public void B(char b){
b = 'B';
System.out.println(" Local b:" + b);
}
public void C(char[] c){
c[0] = 'C';
System.out.println(" Local c:" + c[0]);
}
}
Let's first look at the changes of local variables :
Local variables can be found a,b,c Can change as required .
Let's look at the changes of member variables :

You can find a,b Variables don't change , This also confirms that in java Only the value is passed in the call , No address call .
in other words :
- For basic data types , It realizes value transmission , It's just a parameter , It will not change the original value .
- For reference data types , Operate on this reference , In fact, it is also equivalent to the operation of formal parameters , Will not change the original reference .
- however , As for the The properties of the reference When operating , amount to CPP Address calls in , You can change the value of the attribute of this reference .
summary
1、 For basic type parameters , Re assign parameters in the method body , It does not change the value of the original variable .
2、 For reference type parameters , Reassign references to parameters in the method body , It does not change the reference held by the original variable .
3、 Operation of parameters in the method body , It does not affect the value of the original variable .
4、 The method body operates on the attributes of the object pointed to by the parameter , Will change the attribute value of the object pointed to by the original variable .
Reference from :Java Method by passing parameters to change the value of variables
边栏推荐
- [event preview] cloud digital factory and digital transformation and innovation forum for small and medium-sized enterprises
- Detailed explanation of serial port communication
- 【C语言系列】—深度解剖数据在内存中的存储(二)-浮点型
- 平行云CEO 李岩:CloudXR ,开启通往元宇宙的通道
- 【C语言系列】— 不创造第三个变量,实现两个数的交换
- QML custom tabbar
- Detailed explanation of exit interrupt
- JD cloud and Forrester consulting released a hybrid cloud report that cloud Nativity has become a new engine driving industrial development
- The function of using wechat applet to scan code to log in to the PC web of the system
- C语言文件操作
猜你喜欢

ClickHouse学习(九)clickhouse整合mysql

关于局部变量

Helm chart for Kubernetes

Alibaba cloud and Dingjie software released the cloud digital factory solution to realize the localized deployment of cloud MES system

C language first level pointer

·来一篇编程之路的自我介绍吧·

省市区三级联动(简单又完美)

Container security open source detection tool - veinmind (mirror backdoor, malicious samples, sensitive information, weak password, etc.)

PyQt5:第一章第1节:使用Qt组件创建一个用户界面-介绍

【C语言系列】— 把同学弄糊涂的 “常量” 与 “变量”
随机推荐
365 day challenge leetcode 1000 questions - day 040 design jump table + avoid flooding + find the latest grouping with size M + color ball with reduced sales value
365 day challenge leetcode 1000 questions - day 041 two point search completion anniversary + nth magic number + online election
一维数组练习
Yangyonglin, vice president of Rushi Technology: when traditional industries encounter "digital space"
ClickHouse学习(八)物化视图
Alibaba cloud and Dingjie software released the cloud digital factory solution to realize the localized deployment of cloud MES system
科班同学真的了解未来的职业规划吗?
QML control: combobox
时间复杂度和空间复杂度
51万奖池邀你参战!第二届阿里云ECS CloudBuild开发者大赛来袭
适创科技以云仿真平台,支持“中国智造”升级
利用Poi-tl在word模板表格单元格内一次插入多张图片和多行单元格相同数据自动合并的功能组件
抽象类与接口
GPIO的输入输出详解
Why is Google's internal tools not suitable for you?
【剑指offer】— 详解库函数atoi以及模拟实现atoi函数
EXIT中断详解
JD cloud golden autumn cloud special offer is in progress! Code scanning participation activities
整数溢出和打印
Storage category