当前位置:网站首页>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
边栏推荐
- Basic principle of recursion
- Application of Huffman tree and Huffman coding in file compression
- Camunda 1、Camunda工作流-介绍
- VIM editor use
- Complete ecological map of R & D Efficiency & selection of Devops tools
- 指针
- 321, Jingdong Yanxi × Nlpcc 2022 challenge starts!
- 167. 两数之和 II - 输入有序数组
- QML type: state state
- paddle. Fluid constant calculation error 'nonetype' object has no attribute 'get_ fetch_ list‘
猜你喜欢

JD cloud golden autumn cloud special offer is in progress! Code scanning participation activities

【C语言系列】—文件操作详解(上)

Detailed explanation of GPIO input and output

【C语言系列】— 不创造第三个变量,实现两个数的交换

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

游戏行业弹性计算最佳实践

浅谈范式

The road to success in R & D efficiency of 1000 person Internet companies

全局components组件注册

【C语言系列】—深度解剖数据在内存中的存储(一) 暑假开篇
随机推荐
Alibaba cloud architect details nine trends in the game industry
【剑指offer】— 详解库函数atoi以及模拟实现atoi函数
Day 2
JS deep copy - Notes
Alibaba cloud architect Liang Xu: MES on cloud box helps customers quickly build digital factories
Preemptive appointment | Alibaba cloud shadowless cloud application online conference appointment opens
Using POI TL to insert multiple pictures and the same data of multiple rows of cells into the table cells of word template at one time, it is a functional component for automatic merging
C language one-dimensional array
GPIO的输入输出详解
One dimensional array exercise
游戏行业弹性计算最佳实践
167. 两数之和 II - 输入有序数组
Side effects and sequence points
C语言 一级指针
2022数学建模竞赛暑期培训讲座——最优化方法:目标规划
R & D efficiency | analysis of kubernetes' core technology and Devops' landing experience
【C语言系列】—文件操作详解(上)
终端shell常用命令
Detailed explanation of exit interrupt
指针