如下所示:
package com.lstc.test;public class TestDemo3 {String str = new String("hello");char[] ch = { 'a', 'b' };public static void main(String[] args) {TestDemo3 t = new TestDemo3();t.change(t.str, t.ch);//String是封装类,是值传递,char数组是引用传递System.out.println(t.str + " and " + t.ch[0] + t.ch[1]);}public void change(String str, char[] ch) {str = "test ok";ch[0] = 'c';}}结果是:str任然是hello,ch的第一个元素a变为c
以上就是小编为大家带来的String类型传递是值传递,char[]类型传递是引用传递的实现的全部内容了,希望对大家有所帮助,多多支持武林网~