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).
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
软考中级精品资料免费领
- 历年真题答案解析
- 备考技巧名师总结
- 高频考点精准押题
- 资料下载
- 历年真题
193.9 KB下载数260
191.63 KB下载数245
143.91 KB下载数1139
183.71 KB下载数640
644.84 KB下载数2752
相关文章
发现更多好内容猜你喜欢
AI推送时光机java 函数的参数传递
后端开发2023-06-03golang函数的参数传递
后端开发2024-04-20java 的参数传递
后端开发2023-12-23php函数间的参数传递(值传递/引用传递)
后端开发2022-11-15golang函数中的参数传递
后端开发2024-04-28java参数怎么传递参数
后端开发2020-12-17golang函数Lambda参数传递
后端开发2024-04-23C++ 函数的参数如何传递?
后端开发2024-04-18golang函数匿名函数参数传递
后端开发2024-04-22golang函数嵌套函数参数传递
后端开发2024-04-22php函数参数的传递方法
后端开发2023-06-14golang函数函数作为参数传递
后端开发2024-04-22C++ 函数参数的传递方式
后端开发2024-04-13golang函数参数的传递方式
后端开发2024-04-22golang函数闭包参数传递
后端开发2024-04-22golang函数命名参数传递
后端开发2024-04-23golang函数可变参数传递
后端开发2024-04-22golang函数省略参数传递
后端开发2024-04-22Python 函数作为参数传递
后端开发2023-01-31Python函数参数传递机制
后端开发2023-01-31咦!没有更多了?去看看其它编程学习网 内容吧