Java参数传递

来源:互联网 发布:Ubuntu安装时跨硬盘 编辑:程序博客网 时间:2024/06/06 12:32

Java参数传递

Java参数传递有两种形式,值传递和引用传递。

一、值传递:

值传递只是将原数据的一份拷贝传递过去,修改的只是拷贝数据,原数据不做修改。

二、引用传递:

传递的是数据地址,即会修改原数据。

三、String

String虽然也是引用类型,但是其也是按照值传递来进行的。

public class Test {public static void main(String[] args){Test test=new Test();String s="hello";System.out.println(s);test.change(s);System.out.println(s);}public String change(String name){name="world";return name+"word";}}

输出结果:

hello

hello

3 0
原创粉丝点击