The Java programming language always uses call by value. That means that the method gets a copy of all parameter values.
The Java programming language always uses call by value. That means that the method gets a copy of all parameter values. In particular, the method cannot modify the contents of any parameter variables that are passed to it.
[@more@]For example, consider the following call:
double percent = 10;harry.raiseSalary(percent);
No matter how the method is implemented, we know that after the method call, the value of percent is still 10.
Let us look a little more closely at this situation. Suppose a method tried to triple the value of a method parameter:
public static void tripleValue(double x) // doesn't work{ x = 3 * x;}
Let's call this method:
double percent = 10;tripleValue(percent);
However, this does not work. After the method call, the value of percent is still 10. Here is what happens:
x is initialized with a copy of the value of percent (that is, 10).
--结束END--
本文标题: java 函数的参数传递
本文链接: https://www.lsjlt.com/news/232805.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0