- public class Demo {
-
- String s = new String("good");
- char[] ch = { 'a', 'b', 'c' };
- Person person = new Person("zhangsan", 11);
-
- public static void main(String args[]) {
- Demo t = new Demo();
- t.changer(t.s, t.ch, t.person);
- System.out.println(t.s);
- System.out.println(t.ch);
- System.out.println(t.person.toString());
- }
-
- private void changer(String s2, char[] ch2, Person person) {
- // TODO Auto-generated method stub
- s = "ok";
- ch[0] = 'g';
- // person = new Person("lisi", 22);
- person.name = "lisi";
-
- }
- }
- // 输出结果如下:
- // ok
- // gbc
- // Person [name=zhangsan, age=11]
- //Person [name=lisi, age=11]
- class Person
- {
- public String name = null;
- public int age = 0;
- public Person(String name,int age)
- {
- this.name = name;
- this.age = age;
- }
- public String toString()
- {
- return "Person [name="+name+", age="+age+"]";
- }
- }
复制代码 |